I've read lots of post here in Stackoverflow about this topic but still I had no success.
I'm working with Symfony version 2.2.3
and currently I'm trying to make work the flashbag messegaes in my project, but for some reason when I'm receiving an empty array in my Twig template.
Here is my Controller code:
public function addProductAction($id) {
$session = $this->container->get('session');
// *** Some nive stuff here with session parameters **
$session->set('products', $products);
// Here it is my flashbag code sort like in symfony2 documentation
$session->getFlashBag()->add('notice', 'Your changes were saved!');
$session->save();
return $this->redirect($this->getRequest()->headers->get('referer'));
}
And here my Twig code:
{% for flashMessage in app.session.flashbag.get('notice') %}
<div class="flash-notice">
{{ flashMessage }}
</div>
{%else%}
<div class="flash-notice">
NO MESSAGES
</div>
{% endfor %}
I've done it just like people say in lots of post in the web, but with no luck... Any idea? As I think I'm only doing ONE request, can't understand why it's not working...