From ac6d9f3b9e1cbc521861545e3d54e96920f3210b Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 10 May 2013 17:46:00 -0500 Subject: [PATCH] Revert "fixed example to check if the session exists when getting flash messages to avoid starting sessions when not needed" It seems that there may be something stored in the flash, but you never know, because the session isn't started, so you never check. This reverts commit a5168ad2f46264508b93b60c4c21a21384244662. --- book/controller.rst | 24 ++++++++++-------------- components/http_foundation/sessions.rst | 13 ------------- quick_tour/the_controller.rst | 8 +++----- 3 files changed, 13 insertions(+), 32 deletions(-) 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