I am using Symfony2 flash messages in my forms to build different views after form submit.
So far everything is as expected, but now I want that the session.flash message (just in one form) do not still alive once this form response view has been rendered.
{% if app.session.hasFlash('something') %}
...some code...
{% endif %}
I have researched about that, but apart the official reference with functions to delete this flash, I have not found any information.
Someone knows which one is the best practice to do that? Remove this flash in some particular place (p.e. a controller or event) or maybe exists some option to limit the flash message lifetime.
Since you are just checking this, but not calling – flash still will be housed in session. To trigger session removing – you have to call
getFlash()on it.Currently, the difference between calling
getFlash()andremoveFlash()is only in fact that first method returns value.For your particular case I recommend you to call getFlash() with second argument, which determines default return value in case if requested index does not exist.