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



10.2k

sorry, understand



21.0k

You can also use session flashes (requires started session): ```php $this->flashSession->success("Message!"); ``` to output them with ```php $this->flashSession->output() ``` in any place you want, and not in conjunction with getContent()



10.2k

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



21.0k

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



21.0k

Here's example: ```php 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;
}

``` ```php $di['flash'] = function() { $flash = new MyCoolFlash ([ 'error' => 'alert-direct error', 'notice' => 'alert-direct notice', 'success' => 'alert-direct success', 'warning' => 'alert-direct warning', ]); return $flash; }; ```



10.2k

ok, this is a good