Thanks to visit codestin.com
Credit goes to github.com

Skip to content

#7676 - Flash messages #7684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ and then redirects. The message key (``notice`` in this example) can be anything
you'll use this key to retrieve the message.

In the template of the next page (or even better, in your base layout template),
read any flash messages from the session:
read any flash messages from the session using ``app.flashes()``:

.. configuration-block::

Expand All @@ -416,17 +416,17 @@ read any flash messages from the session:
{# app/Resources/views/base.html.twig #}

{# you can read and display just one flash message type... #}
{% for flash_message in app.session.flashBag.get('notice') %}
{% for message in app.flashes('notice') %}
<div class="flash-notice">
{{ flash_message }}
{{ message }}
</div>
{% endfor %}

{# ...or you can read and display every flash message available #}
{% for type, flash_messages in app.session.flashBag.all %}
{% for flash_message in flash_messages %}
<div class="flash-{{ type }}">
{{ flash_message }}
{% for label, messages in app.flashes %}
{% for message in messages %}
<div class="flash-{{ label }}">
{{ message }}
</div>
{% endfor %}
{% endfor %}
Expand All @@ -451,6 +451,10 @@ read any flash messages from the session:
<?php endforeach ?>
<?php endforeach ?>

.. versionadded:: 3.3
The ``app.flashes()`` method was introduced in Symfony 3.3. Prior to version 3.3
you had to use ``app.session.flashBag``.

.. note::

It's common to use ``notice``, ``warning`` and ``error`` as the keys of the
Expand Down
8 changes: 6 additions & 2 deletions quick_tour/the_controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,16 @@ And you can display the flash message in the template like this:

.. code-block:: html+twig

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

.. versionadded:: 3.3
The ``app.flashes()`` method was introduced in Symfony 3.3. Prior to version 3.3
you had to use ``app.session.flashBag``.

Final Thoughts
--------------

Expand Down
12 changes: 8 additions & 4 deletions session/avoid_session_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ that a session is *always* started:

.. code-block:: html+twig

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

Expand All @@ -30,9 +30,13 @@ access the flash messages:
.. code-block:: html+twig

{% if app.request.hasPreviousSession %}
{% for flashMessage in app.session.flashBag.get('notice') %}
{% for message in app.flashes('notice') %}
<div class="flash-notice">
{{ flashMessage }}
{{ message }}
</div>
{% endfor %}
{% endif %}

.. versionadded:: 3.3
The ``app.flashes()`` method was introduced in Symfony 3.3. Prior to version 3.3
you had to use ``app.session.flashBag``.