Skip to content

Commit e6556b5

Browse files
miguelvilataxabbuh
authored andcommitted
Update controller.rst
Hello. It's neccesary clarify that flash messages aren't removed automatically when next session comes. They are removed because the use of get method in FlashBag object. If you use peek() method, or simply don't show stored messages they remain in session. Show get() method in Symfony\Component\HttpFoundation\Session\Flash\FlashBag: /** * {@inheritdoc} */ public function get($type, array $default = array()) { if (!$this->has($type)) { return $default; } $return = $this->flashes[$type]; unset($this->flashes[$type]); return $return; }
1 parent 6d3e0f0 commit e6556b5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

book/controller.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,8 @@ session.
604604
Flash Messages
605605
~~~~~~~~~~~~~~
606606

607-
You can also store small messages that will be stored on the user's session
608-
for exactly one additional request. This is useful when processing a form:
607+
You can also store small messages that will be stored on the user's session.
608+
This is useful when processing a form:
609609
you want to redirect and have a special message shown on the *next* page.
610610
These types of messages are called "flash" messages.
611611

@@ -658,9 +658,17 @@ the following code will render the ``notice`` message:
658658
</div>
659659
<?php endforeach ?>
660660

661-
By design, flash messages are meant to live for exactly one request (they're
662-
"gone in a flash"). They're designed to be used across redirects exactly as
663-
you've done in this example.
661+
.. tip::
662+
663+
By design, flash messages are meant to be processed exactly once. This means
664+
that they vanish from the session automatically when they are retrieved from
665+
the flash bag by calling the ``get()`` method.
666+
667+
.. tip::
668+
669+
You can use the
670+
:method:`Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface::peek()`
671+
method instead to retrieve the message while keeping it in the bag.
664672

665673
.. index::
666674
single: Controller; Response object

0 commit comments

Comments
 (0)