cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Printing Flash\Session messages in layouts

Open emrecdr opened this issue 13 years ago • 3 comments

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() ?>

emrecdr avatar Dec 20 '12 23:12 emrecdr

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;

ghost avatar Dec 21 '12 01:12 ghost

Thanks for your reply. After making changes as you mentioned, I can be able to display Flash\Session messages in layouts now.

emrecdr avatar Dec 21 '12 21:12 emrecdr

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

djbitu18 avatar Mar 11 '15 14:03 djbitu18