Flash message disappears when redirected in Symfony 2.1

I am transitioning from Symfony 2.0 to Symfony 2.1.

I have the following simple code on my controller:

public function createEntidadeAction() {
    $this->get('session')->getFlashBag()->set('error', 'message');
    return $this->redirect($this->generateUrl('EntidadeBundle_index'));
}

If I generate an error (for example, skipping an unsuccessful route), I will check the profiler that there is a flash message there.

However, if I allow redirecting to success, the error message will disappear and nothing will be displayed. I am using the following Twig pattern:

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

I can’t figure it out. What am I missing? Pop-up messages should last after the first redirect, no?

+5
source share
2 answers

I get it.

Flash messages did not appear due to session problems.

Symfony 2.1 now uses session.storage.native for storage_id and handler_id by default.

, , .

+6

add set -. -, , :

{% for type, flashMessages in app.session.flashbag.all() %}
    {% for flashMessage in flashMessages %}
        <div class="alert alert-{{ type }}">
            {{ flashMessage|trans }}
        </div>
    {% endfor %}
{% endfor %}
+6

All Articles