Hello Friends,
If you are looking to flash success messages in Symfony. Please review the code below:
1) Open your controller and put the below code with your changes:
// Define your success message as below
$request->getSession()
->getFlashBag()
->add('success', 'Entity has been added succesfully!');
// Redirect to your specific file
return $this->redirectToRoute('master_reginalentity_list');
2) Now open your view(.twig) file where you want to display this message and put the below code at your location:
{% if app.session.flashBag.has('success') %}
<div class="alert alert-success">
{% for msg in app.session.flashBag.get('success') %}
{{ msg }}
{% endfor %}
</div>
{% endif %}
Thank you
0 Comment(s)