We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Flashing Messages

add in controller $this->flash->success("The post was correctly saved!"); and how to display messages in html? I have no messages appear


sorry, understand


You can also use session flashes (requires started session):


to output them with


in any place you want, and not in conjunction with getContent()


$this->flashSession->output(); with \Phalcon\Flash\Direct() no work what indicate exact place for showing the message in this case?


It works with Phalcon\Flash\Session. Direct outputs his contents at the top of action render level. Other words — right at the place where you placed <?=$this->getContent()?> in your action view .phtml If you want place flashes in needed place without sessions you can easily extend Phalcon\Flash with own class storing messages into variable and outputs where the output() called. I did so =)


Here's example:

class MyCoolFlash extends Phalcon\Flash implements Phalcon\FlashInterface
     * Contains all nonouputed messages
    private $messages = "";

    //override constructor
    public function __construct($cssClasses)
        parent::setImplicitFlush(false); // don't output when parent::outputMessage() called
        parent::setAutomaticHtml(true); // enable html because of disabled by default

    public function error($message)
        $this->messages .= parent::error($message);
    // and other types ...

    public function output()
        return $this->messages;
    $di['flash'] = function() {
        $flash = new MyCoolFlash ([
            'error'   => 'alert-direct error',
            'notice'  => 'alert-direct notice',
            'success' => 'alert-direct success',
            'warning' => 'alert-direct warning',
        return $flash;


ok, this is a good