Skip to content

Commit d9ff31e

Browse files
committed
minor #5808 Reworded the explanation about flash messages (javiereguiluz)
This PR was merged into the 2.3 branch. Discussion ---------- Reworded the explanation about flash messages | Q | A | ------------- | --- | Doc fix? | no | New docs? | no | Applies to | all | Fixed tickets | - As any reword, most of its changes are debatable. However, I think that the reword is better than the current explanation in one thing: the feature that makes flash message self-vanish as soon as they are retrieved is essential to understand their behavior. In my opinion is wrong to explain that in a `.. note` admonition at the end of the section. Commits ------- e38b037 Fixed a RST syntax issue 747f10b Reworded the explanation about flash messages
2 parents 52373ae + e38b037 commit d9ff31e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

book/controller.rst

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

607-
You can also store small messages that will be stored on the user's session.
608-
This is useful when processing a form:
609-
you want to redirect and have a special message shown on the *next* page.
610-
These types of messages are called "flash" messages.
607+
You can also store special messages, called "flash" messages, on the user's
608+
session. By design, flash messages are meant to be processed exactly once. This
609+
means that they vanish from the session automatically as soon as they are
610+
retrieved. This feature makes "flash" messages particularly suited for storing
611+
user notifications.
611612

612-
For example, imagine you're processing a form submit::
613+
Consider the following form processing example::
613614

614615
use Symfony\Component\HttpFoundation\Request;
615616

@@ -633,12 +634,12 @@ For example, imagine you're processing a form submit::
633634
return $this->render(...);
634635
}
635636

636-
After processing the request, the controller sets a ``notice`` flash message
637-
in the session and then redirects. The name (``notice``) isn't significant -
638-
it's just something you invent and reference next.
637+
After processing the request, the controller sets a flash message in the session
638+
and then redirects. The message key (``notice`` in this example) can be freely
639+
chosen and is used to retrieve the message content.
639640

640641
In the template of the next page (or even better, in your base layout template),
641-
the following code will render the ``notice`` message:
642+
the following code will render the messages stored under the ``notice`` key:
642643

643644
.. configuration-block::
644645

@@ -660,9 +661,9 @@ the following code will render the ``notice`` message:
660661

661662
.. note::
662663

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.
664+
It's common to use ``notice``, ``warning`` and ``error`` as the keys of the
665+
different types of flash messages, but you can use any key that fits your
666+
needs.
666667

667668
.. tip::
668669

0 commit comments

Comments
 (0)