File tree 3 files changed +13
-32
lines changed
components/http_foundation
3 files changed +13
-32
lines changed Original file line number Diff line number Diff line change @@ -686,23 +686,19 @@ the ``notice`` message:
686
686
687
687
.. code-block :: html+jinja
688
688
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 %}
696
694
697
695
.. code-block :: html+php
698
696
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; ?>
706
702
707
703
By design, flash messages are meant to live for exactly one request (they're
708
704
"gone in a flash"). They're designed to be used across redirects exactly as
Original file line number Diff line number Diff line change @@ -333,16 +333,3 @@ Compact method to process display all flashes at once::
333
333
echo "<div class='flash-$type'>$message</div>\n";
334
334
}
335
335
}
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
- }
Original file line number Diff line number Diff line change @@ -141,11 +141,9 @@ next request::
141
141
142
142
// display any messages back in the next request (in a template)
143
143
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 %}
149
147
150
148
This is useful when you need to set a success message before redirecting
151
149
the user to another page (which will then show the message). Please note that
You can’t perform that action at this time.
0 commit comments