From cf8e7341aa7a74bc6b068ebff00e38a2f289e4cd Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 31 Jan 2017 10:04:31 +0100 Subject: [PATCH 1/3] Explain how to get all flash messages --- controller.rst | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/controller.rst b/controller.rst index d2cb16261f1..48b0bf13380 100644 --- a/controller.rst +++ b/controller.rst @@ -188,8 +188,8 @@ For more information, see the :doc:`Routing chapter `. .. caution:: - The ``redirect()`` method does not check its destination in any way. If you - redirect to some URL provided by the end-users, your application may be open + The ``redirect()`` method does not check its destination in any way. If you + redirect to some URL provided by the end-users, your application may be open to the `unvalidated redirects security vulnerability`_. @@ -425,21 +425,43 @@ read any flash messages from the session: .. code-block:: html+twig {# 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') %}
{{ flash_message }}
{% endfor %} + {# ...or you can read and display every flash message that exists #} + {% for type, flash_messages in app.session.flashBag.all %} + {% for flash_message in flash_messages %} +
+ {{ flash_message }} +
+ {% endif %} + {% endfor %} + .. code-block:: html+php + + // you can read and display just one flash message type... getFlash('notice') as $message): ?>
- $message
" ?> + + // ...or you can read and display every flash message that exists + getFlashes() as $type => $flash_messages): ?> + +
+ +
+ + + .. note:: It's common to use ``notice``, ``warning`` and ``error`` as the keys of the From 51dfdf9ad1da8ddb5340534d0c9f68db5ba2627d Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 31 Jan 2017 10:05:36 +0100 Subject: [PATCH 2/3] Simplified the Twig code with the Session helpers --- controller.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controller.rst b/controller.rst index 48b0bf13380..975a60fb1cf 100644 --- a/controller.rst +++ b/controller.rst @@ -427,14 +427,14 @@ 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 flash_message in app.session.flash('notice') %}
{{ flash_message }}
{% endfor %} {# ...or you can read and display every flash message that exists #} - {% for type, flash_messages in app.session.flashBag.all %} + {% for type, flash_messages in app.session.flashes %} {% for flash_message in flash_messages %}
{{ flash_message }} From 380d703a4f34f77f9778e8143c7a17b798eb7c26 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 1 Feb 2017 08:49:23 +0100 Subject: [PATCH 3/3] Minor change --- controller.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controller.rst b/controller.rst index 975a60fb1cf..ab04d9ecb51 100644 --- a/controller.rst +++ b/controller.rst @@ -433,7 +433,7 @@ read any flash messages from the session:
{% endfor %} - {# ...or you can read and display every flash message that exists #} + {# ...or you can read and display every flash message available #} {% for type, flash_messages in app.session.flashes %} {% for flash_message in flash_messages %}
@@ -453,7 +453,7 @@ read any flash messages from the session:
- // ...or you can read and display every flash message that exists + // ...or you can read and display every flash message available getFlashes() as $type => $flash_messages): ?>