Printing Flash\Session messages in layouts
When I register for Session Flashing Messages and then store a message, I can print manually the message only in the corresponding action view. But I need to print those session messages in Layout files.
//Register the flash service with custom CSS classes $di->set('flashSession', function(){ // Temporarily stores the messages in session, then messages can be printed in the next request $flashSession = new \Phalcon\Flash\Session(); return $flashSession; });
public function saveAction()
{
//store the post
//Using session flash
$this->flashSession->success("Your information were stored correctly!");
//Make a full HTTP redirection
return $this->response->redirect("contact/index");
}
works only in app/views/contact/index.phtml:
flashSession->output() ?>
Hi siluet, please make sure you're starting the session in your 'session' service registration:
$di->set('session', function(){
$session = new Phalcon\Session\Adapter\Files();
$session->start();
return $session;
}, true);
By the other hand, note that response->redirect doesn't stop the auto-rendering mode in the view component, maybe the messages are being printed and you aren't noticed of that:
$this->response->redirect("contact/index");
$this->view->disable();
return;
Thanks for your reply. After making changes as you mentioned, I can be able to display Flash\Session messages in layouts now.
The same problem is with me also
i write the following code in the controller
$this->flashSession->success($this->request->getPost("first_name").' Updated successsfully . . .'); return $this->dispatcher->forward(array("controller"=>"users","action" => "index"));
and would like to view the flash message in the view page but i am unable to design the flash
plz help me on this