Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Flash in Symfony 2.1

I have been adapting our code in preparation of moving our code to the new 2.1 Symfony codebase.

In 2.0.* we could set Flash messages by simply calling the session service in our controller using the following

$this->get('session')->setFlash('type', 'message');

I have trawled through the new documentation, I was just wondering if there was a clean way, similar to the above; rather than just calling the FlashBagInterface?

like image 936
michaelotoole Avatar asked Mar 07 '12 09:03

michaelotoole


2 Answers

Try:

$this->get('session')->getFlashBag()->set('type', 'message');
like image 93
Mr Pablo Avatar answered Nov 09 '22 18:11

Mr Pablo


Also, you might want to try the add() method instead, which won't obliterate other flash messages:

$this->get('session')->getFlashBag()->add('type', 'message');
like image 13
theunraveler Avatar answered Nov 09 '22 20:11

theunraveler