diff --git a/book/controller.rst b/book/controller.rst index b5ea88967c9..6916753b236 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -686,23 +686,19 @@ the ``notice`` message: .. code-block:: html+jinja - {% if app.session.started %} - {% for flashMessage in app.session.flashbag.get('notice') %} -
- {{ flashMessage }} -
- {% endfor %} - {% endif %} + {% for flashMessage in app.session.flashbag.get('notice') %} +
+ {{ flashMessage }} +
+ {% endfor %} .. code-block:: html+php - isStarted()): ?> - getFlashBag()->get('notice') as $message): ?> -
- $message
" ?> - - - + getFlashBag()->get('notice') as $message): ?> +
+ $message
" ?> + + By design, flash messages are meant to live for exactly one request (they're "gone in a flash"). They're designed to be used across redirects exactly as diff --git a/components/http_foundation/sessions.rst b/components/http_foundation/sessions.rst index 559d699eae0..dbd855f4bf0 100644 --- a/components/http_foundation/sessions.rst +++ b/components/http_foundation/sessions.rst @@ -333,16 +333,3 @@ Compact method to process display all flashes at once:: echo "
$message
\n"; } } - -.. caution:: - - As flash messages use a session to store the messages from one request to - the next one, a session will be automatically started when you read the - flash messages even if none already exists. To avoid that default - behavior, test if there is an existing session first:: - - if ($session->isStarted()) { - foreach ($session->getFlashBag()->get('warning', array()) as $message) { - echo "
$message
"; - } - } diff --git a/quick_tour/the_controller.rst b/quick_tour/the_controller.rst index 67b66b8b60f..c11c5473140 100755 --- a/quick_tour/the_controller.rst +++ b/quick_tour/the_controller.rst @@ -141,11 +141,9 @@ next request:: // display any messages back in the next request (in a template) - {% if app.session.started %} - {% for flashMessage in app.session.flashbag.get('notice') %} -
{{ flashMessage }}
- {% endfor %} - {% endif %} + {% for flashMessage in app.session.flashbag.get('notice') %} +
{{ flashMessage }}
+ {% endfor %} This is useful when you need to set a success message before redirecting the user to another page (which will then show the message). Please note that