Skip to content

Update controller.rst clarifying automatic deletion for flash messages #5640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions book/controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,8 @@ session.
Flash Messages
~~~~~~~~~~~~~~

You can also store small messages that will be stored on the user's session
for exactly one additional request. This is useful when processing a form:
You can also store small messages that will be stored on the user's session.
This is useful when processing a form:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like something went wrong here (this doesn't match the following line)

you want to redirect and have a special message shown on the *next* page.
These types of messages are called "flash" messages.

Expand Down Expand Up @@ -658,9 +658,17 @@ the following code will render the ``notice`` message:
</div>
<?php endforeach ?>

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
you've done in this example.
.. tip::

By design, flash messages are meant to be processed exactly once. This means
that they vanish from the session automatically when they are retrieved from
the flash bag by calling the ``get()`` method.

.. tip::

You can use the
:method:`Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface::peek()`
method instead to retrieve the message while keeping it in the bag.

.. index::
single: Controller; Response object
Expand Down