Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

#7676 - Flash messages#7684

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
ghost wants to merge4 commits intosymfony:masterfromunknown repository
Closed
Show file tree
Hide file tree
Changes fromall 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: 11 additions & 7 deletionscontroller.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -407,7 +407,7 @@ and then redirects. The message key (``notice`` in this example) can be anything
you'll use this key to retrieve the message.

In the template of the next page (or even better, in your base layout template),
read any flash messages from the session:
read any flash messages from the session using ``app.flashes()``:

.. configuration-block::

Expand All@@ -416,17 +416,17 @@ read any flash messages from the session:
{# app/Resources/views/base.html.twig #}

{# you can read and display just one flash message type... #}
{% forflash_message in app.session.flashBag.get('notice') %}
{% formessage in app.flashes('notice') %}
<div class="flash-notice">
{{flash_message }}
{{message }}
</div>
{% endfor %}

{# ...or you can read and display every flash message available #}
{% fortype, flash_messages in app.session.flashBag.all %}
{% forflash_message inflash_messages %}
<div class="flash-{{type }}">
{{flash_message }}
{% forlabel, messages in app.flashes %}
{% formessage inmessages %}
<div class="flash-{{label }}">
{{message }}
</div>
{% endfor %}
{% endfor %}
Expand All@@ -451,6 +451,10 @@ read any flash messages from the session:
<?php endforeach ?>
<?php endforeach ?>

.. versionadded:: 3.3
The ``app.flashes()`` method was introduced in Symfony 3.3. Prior to version 3.3
you had to use ``app.session.flashBag``.

.. note::

It's common to use ``notice``, ``warning`` and ``error`` as the keys of the
Expand Down
8 changes: 6 additions & 2 deletionsquick_tour/the_controller.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -331,12 +331,16 @@ And you can display the flash message in the template like this:

..code-block::html+twig

{% forflashMessage in app.session.flashBag.get('notice') %}
{% formessage in app.flashes('notice') %}
<div class="flash-notice">
{{flashMessage }}
{{message }}
</div>
{% endfor %}

..versionadded::3.3
The ``app.flashes()`` method was introduced in Symfony 3.3. Prior to version 3.3
you had to use ``app.session.flashBag``.

Final Thoughts
--------------

Expand Down
12 changes: 8 additions & 4 deletionssession/avoid_session_start.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,9 @@ that a session is *always* started:

..code-block::html+twig

{% forflashMessage in app.session.flashBag.get('notice') %}
{% formessage in app.flashes('notice') %}
<div class="flash-notice">
{{flashMessage }}
{{message }}
</div>
{% endfor %}

Expand All@@ -30,9 +30,13 @@ access the flash messages:
..code-block::html+twig

{% if app.request.hasPreviousSession %}
{% forflashMessage in app.session.flashBag.get('notice') %}
{% formessage in app.flashes('notice') %}
<div class="flash-notice">
{{flashMessage }}
{{message }}
</div>
{% endfor %}
{% endif %}

..versionadded::3.3
The ``app.flashes()`` method was introduced in Symfony 3.3. Prior to version 3.3
you had to use ``app.session.flashBag``.

[8]ページ先頭

©2009-2025 Movatter.jp