David Egger
David Egger

Reputation: 21

Symfony 2.8.2 flashmessage and redirecttoroute

I'm using Symfony 2.8.2 and somehow the FlashMessage does not live through a redirect.

$this->addFlash('success', 'Expedition erfolgreich!');
return $this->redirectToRoute('mainmenu_dashboard');

After the redirect there is no flashmessage. I already looked in the session (dumped it) but there is no flash message after the redirect.

Any ideas?

Upvotes: 1

Views: 1739

Answers (2)

David Egger
David Egger

Reputation: 21

Thank's for your answer!

I discovered the problem somewhere else. I used session_write_close() somewhere else to set the session to not blocking (to be able to cancel a request). This was the reason why session was not writeable at this point anymore!

Upvotes: 0

Egg
Egg

Reputation: 1769

You'll need to check for, and display, the flashMessage in your twig template for the mainmenu_dashboard route.

For example:

{% for flashMessage in app.session.flashbag.get('success') %}
    <div class="success">{{ flashMessage }}</div>
{% endfor %}

The flash will exist in session, between routes, until they are used.

Symfony Doc

Upvotes: 1

Related Questions