-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add flash messages #163
Conversation
Import macros used for displaying flash messages. | ||
See http://twig.sensiolabs.org/doc/tags/import.html | ||
#} | ||
{% import 'macro/messages.html.twig' as helper %} |
There was a problem hiding this comment.
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') %} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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").
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
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
This adds German translations for the flash messages added in symfony#163.
This finishes #158 by simplifying its contents.