We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Is it possible to get the number of \Phalcon\Flash per message category

I would like to know if it's possible to get the total number of \Phalcon\Flash message per category Something like

$this->flash->totalError();
$this->flash->totalWarning();
$this->flash->totalNotice();
$this->flash->totalSuccess();


98.9k

No, Phalcon\Flash does not have such functionality. Perphaps you can create your own Flash class implementing that functionality:

class Flash extends Phalcon\Flash\Direct
{
    public function totalError()
    { 
        //...
    }
}


2.0k

I think I found the answer I was seeking

It's possible to do it via the Phalcon\Flash\Session (I think, haven't tested yet, I'm going to edit this comment as soon as I will)

In the doc : https://docs.phalcon.io/en/latest/api/Phalcon_Flash_Session.html

public has (unknown $type)
    bool \Phalcon\Flash\Session::has(string $type)

and

public array getMessages ([string $type], [boolean $remove])
    Returns the messages in the session flasher

So it would be possible to do :

if($this->flashSession->has("error")){
    [...]
}
//or
if(count($this->flashSession->getMessages("error", false)) >= $myVar){
    [...]
}