Flash messages can be really useful when you want to display a message to your user.
That is basically what flash messages do. They store some text in session to be available only in the next request. After that the message is deleted.
Zend Framework 2 has a view helper that makes using flash messages a walk in the park. Let’s see how to use it.
First of all we need a place to show the messages. Usually I place it in my layout file so I can use it from any controller in my application.
1 2 3 4 5 6 7 8 9 10 11 12
In the code above I’m wrapping the message with the standard Bootstrap CSS classes to generate nice alert boxes.
Now, from your controller, all you have to do is this:
1 2 3
Or for a success message:
1 2 3
That’s all folks.