Skip to content

Commit ac6d9f3

Browse files
committed
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 a5168ad.
1 parent 0d5a095 commit ac6d9f3

File tree

3 files changed

+13
-32
lines changed

3 files changed

+13
-32
lines changed

book/controller.rst

+10-14
Original file line numberDiff line numberDiff line change
@@ -686,23 +686,19 @@ the ``notice`` message:
686686

687687
.. code-block:: html+jinja
688688

689-
{% if app.session.started %}
690-
{% for flashMessage in app.session.flashbag.get('notice') %}
691-
<div class="flash-notice">
692-
{{ flashMessage }}
693-
</div>
694-
{% endfor %}
695-
{% endif %}
689+
{% for flashMessage in app.session.flashbag.get('notice') %}
690+
<div class="flash-notice">
691+
{{ flashMessage }}
692+
</div>
693+
{% endfor %}
696694

697695
.. code-block:: html+php
698696

699-
<?php if ($view['session']->isStarted()): ?>
700-
<?php foreach ($view['session']->getFlashBag()->get('notice') as $message): ?>
701-
<div class="flash-notice">
702-
<?php echo "<div class='flash-error'>$message</div>" ?>
703-
</div>
704-
<?php endforeach; ?>
705-
<?php endif; ?>
697+
<?php foreach ($view['session']->getFlashBag()->get('notice') as $message): ?>
698+
<div class="flash-notice">
699+
<?php echo "<div class='flash-error'>$message</div>" ?>
700+
</div>
701+
<?php endforeach; ?>
706702

707703
By design, flash messages are meant to live for exactly one request (they're
708704
"gone in a flash"). They're designed to be used across redirects exactly as

components/http_foundation/sessions.rst

-13
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,3 @@ Compact method to process display all flashes at once::
333333
echo "<div class='flash-$type'>$message</div>\n";
334334
}
335335
}
336-
337-
.. caution::
338-
339-
As flash messages use a session to store the messages from one request to
340-
the next one, a session will be automatically started when you read the
341-
flash messages even if none already exists. To avoid that default
342-
behavior, test if there is an existing session first::
343-
344-
if ($session->isStarted()) {
345-
foreach ($session->getFlashBag()->get('warning', array()) as $message) {
346-
echo "<div class='flash-warning'>$message</div>";
347-
}
348-
}

quick_tour/the_controller.rst

+3-5
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,9 @@ next request::
141141

142142
// display any messages back in the next request (in a template)
143143

144-
{% if app.session.started %}
145-
{% for flashMessage in app.session.flashbag.get('notice') %}
146-
<div>{{ flashMessage }}</div>
147-
{% endfor %}
148-
{% endif %}
144+
{% for flashMessage in app.session.flashbag.get('notice') %}
145+
<div>{{ flashMessage }}</div>
146+
{% endfor %}
149147

150148
This is useful when you need to set a success message before redirecting
151149
the user to another page (which will then show the message). Please note that

0 commit comments

Comments
 (0)