Hello Friends,
If you are looking to flash error message in Symfony. Please review the code as below:
Please open your controller function where you need to display error message. Please review the below example and update your code accordingly:
$request->getSession()
->getFlashBag()
->add('error', "!! Error YOUR ERROR MESSAGE");
return $this->redirectToRoute('pis_setUserCredential_update', array('id' => $params['id']));
// pis_setUserCredential_update would be replace by your path and in array you can pass your variables
Now open your twig(view) file and update your code as per below example:
{% for flash_message in app.session.flashBag.get('error') %}
<div class="alert alert-warning" role="alert">
{{ flash_message }}
</div>
{% endfor %}
0 Comment(s)