We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 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



17.0k

sorry, understand



32.5k

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

$this->flashSession->success("Message!");

to output them with

$this->flashSession->output()

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



17.0k

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



32.5k

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 =)



32.5k

Here's example:

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

    //override constructor
    public function __construct($cssClasses)
    {
        parent::__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;
    };


17.0k

ok, this is a good