I'm trying for the first time to set and then display a flash message in a Symfony2 application. A flash message being set is not cleared once displayed for the first time.
I set a flash message in a controller action:
public function startAction()
{
if (!$this->hasError()) {
$this->get('session')->setFlash('test_start_error', '');
return $this->redirect($this->generateUrl('app', array(), true));
}
}
And in the corresponding view I display an error notification if the relevant flash key is set:
{% if app.session.hasFlash('test_start_error') %}
error content here
{% endif %}
Under the correct error conditions, the controller sets the flash message and the relevant error content is presented in the view.
Once displayed, the flash message is presented again request after request.Examining the relevant session data via var_dump($this->get('session')->getFlashBag());
reveals that the flash content remains in the session.
I was under the impression that a flash message, having been displayed once, is removed from the session. This is not happening for me.
Clearly I'm doing something wrong - what is it?