Skip to content
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

Add flash messages #163

Merged
merged 10 commits into from
Sep 7, 2015
Merged

Add flash messages #163

merged 10 commits into from
Sep 7, 2015

Conversation

javiereguiluz
Copy link
Member

This finishes #158 by simplifying its contents.

Import macros used for displaying flash messages.
See http://twig.sensiolabs.org/doc/tags/import.html
#}
{% import 'macro/messages.html.twig' as helper %}
Copy link
Member

Choose a reason for hiding this comment

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

same comment that in the original PR. Importing macros in the parent to use them in the child is not a supported way to use macros and will be removed in Twig 2.x

{% from _self import alert %}

<div class="messages">
{% for flash_message in app.session.flashBag.get('success') %}
Copy link
Member

Choose a reason for hiding this comment

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

this will start a session even if the user has no session yet. You should wrap this in a if app.session.started check

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I still belive this is a Symfony bug ... but until it's fixed, let's use the if ... trick.

Copy link
Member

Choose a reason for hiding this comment

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

well, you are asking to read from the session. currently, Symfony requires to start the session to read from it. There is proposal to change it, but it cannot be considered as a bugfix (it is a big refactoring), and I'm not sure it is ready.

@@ -87,6 +87,11 @@ public function newAction(Request $request)
$em->persist($post);
$em->flush();

// Flash messages are used to notify the user about the result of the
// actions. They only last as long as the next request.
Copy link
Member

Choose a reason for hiding this comment

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

We should improve this description like we did in the docs (flash messages last until they are retrieved from the bag).

Copy link
Member Author

Choose a reason for hiding this comment

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

Where can I find the updated explanation? In http://symfony.com/doc/current/book/controller.html#flash-messages I read:

You can also store small messages that will be stored on the user's session for exactly one additional request. [...]

[...] By design, flash messages are meant to live for exactly one request (they're "gone in a flash").

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, it's not merged yet (see symfony/symfony-docs#5640).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the reference. I've just reworded this help note in 3eefa76.

@javiereguiluz javiereguiluz merged commit 3eefa76 into symfony:master Sep 7, 2015
javiereguiluz added a commit that referenced this pull request Sep 7, 2015
This PR was merged into the master branch.

Discussion
----------

Add flash messages

This finishes #158 by simplifying its contents.

Commits
-------

3eefa76 Reworded the help note about flash messages
9a8d43d Check if the session exists before reading flash messages
d01311b Transformed the macro() of the Flash messages into a regular include() template
f481eef Refactored the template code related to macros
da04216 Fixed an issue with the translation file after the rebase
51f7262 Restored the content database
7507a50 Simplified the template code used to render flash messages
a46c948 Use 'success' as the name of the messages related to success messages
12bd670 Update Russian and English translations
0680841 Show flash messages after creating, updating and deleting posts
xabbuh added a commit to xabbuh/symfony-demo that referenced this pull request Sep 7, 2015
This adds German translations for the flash messages added in symfony#163.
javiereguiluz added a commit that referenced this pull request Sep 8, 2015
This PR was squashed before being merged into the master branch (closes #178).

Discussion
----------

German translations for flash messages

This adds German translations for the flash messages added in #163.

Commits
-------

af2192d German translations for flash messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants