Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 467de14

Browse filesBrowse files
ricardodevriesxabbuh
authored andcommitted
#7676 - Flash messages
1 parent 01b10f1 commit 467de14
Copy full SHA for 467de14

File tree

3 files changed

+25
-13
lines changed
Filter options

3 files changed

+25
-13
lines changed

‎controller.rst

Copy file name to clipboardExpand all lines: controller.rst
+11-7Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ and then redirects. The message key (``notice`` in this example) can be anything
407407
you'll use this key to retrieve the message.
408408

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

412412
.. configuration-block::
413413

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

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

425425
{# ...or you can read and display every flash message available #}
426-
{% for type, flash_messages in app.session.flashBag.all %}
427-
{% for flash_message in flash_messages %}
428-
<div class="flash-{{ type }}">
429-
{{ flash_message }}
426+
{% for label, messages in app.flashes %}
427+
{% for message in messages %}
428+
<div class="flash-{{ label }}">
429+
{{ message }}
430430
</div>
431431
{% endfor %}
432432
{% endfor %}
@@ -451,6 +451,10 @@ read any flash messages from the session:
451451
<?php endforeach ?>
452452
<?php endforeach ?>
453453

454+
.. versionadded:: 3.3
455+
The ``app.flashes()`` method was introduced in Symfony 3.3. Prior to version 3.3
456+
you had to use ``app.session.flashBag``.
457+
454458
.. note::
455459

456460
It's common to use ``notice``, ``warning`` and ``error`` as the keys of the

‎quick_tour/the_controller.rst

Copy file name to clipboardExpand all lines: quick_tour/the_controller.rst
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,16 @@ And you can display the flash message in the template like this:
331331

332332
.. code-block:: html+twig
333333

334-
{% for flashMessage in app.session.flashBag.get('notice') %}
334+
{% for message in app.flashes('notice') %}
335335
<div class="flash-notice">
336-
{{ flashMessage }}
336+
{{ message }}
337337
</div>
338338
{% endfor %}
339339

340+
.. versionadded:: 3.3
341+
The ``app.flashes()`` method was introduced in Symfony 3.3. Prior to version 3.3
342+
you had to use ``app.session.flashBag``.
343+
340344
Final Thoughts
341345
--------------
342346

‎session/avoid_session_start.rst

Copy file name to clipboardExpand all lines: session/avoid_session_start.rst
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ that a session is *always* started:
1515

1616
.. code-block:: html+twig
1717

18-
{% for flashMessage in app.session.flashBag.get('notice') %}
18+
{% for message in app.flashes('notice') %}
1919
<div class="flash-notice">
20-
{{ flashMessage }}
20+
{{ message }}
2121
</div>
2222
{% endfor %}
2323

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

3232
{% if app.request.hasPreviousSession %}
33-
{% for flashMessage in app.session.flashBag.get('notice') %}
33+
{% for message in app.flashes('notice') %}
3434
<div class="flash-notice">
35-
{{ flashMessage }}
35+
{{ message }}
3636
</div>
3737
{% endfor %}
3838
{% endif %}
39+
40+
.. versionadded:: 3.3
41+
The ``app.flashes()`` method was introduced in Symfony 3.3. Prior to version 3.3
42+
you had to use ``app.session.flashBag``.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.