Set Flash in Symfony 2.1

michaelotoole picture michaelotoole · Mar 7, 2012 · Viewed 9.2k times · Source

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?

Answer

Mr Pablo picture Mr Pablo · Mar 7, 2012

Try:

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