Symfony bundle to handle symfony flash messages called by ajax actions
Bundle will catch all FlashBag messages set in ajax actions in controllers when send an request via jquery and display it as it would show flash messages used in normal symfony controller actions. You can override flash message styles as you wish. At the moment they should look quite user friendly/UX.
Add AjaxFlashMessageBundle in your composer.json file:
{
"require": {
"hawk6/ajax-flash-message-bundle": "~1.0"
}
}
Now tell Composer to download the bundle by running the command:
php composer.phar update hawk6/ajax-flash-message-bundle
Composer will install the bundle to your project's vendor/aretusa directory.
Enable the bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Ajax\Bundle\FlashMessageBundle(),
);
}
php app/console assets:install web --symlink --relative
In layout file:
{{ include('AjaxFlashMessageBundle::flash-messages.html.twig') }}
Add jQuery as well if it's not already done.
{% block javascripts %}
// ...
<script src="//code.jquery.com/jquery-2.2.2.min.js" type="text/javascript"></script>
<script src="{{ asset('bundles/ajaxflashmessage/js/jquery.flash-messenger.js') }}" type="text/javascript"></script>
{% endblock %}
{% block stylesheets %}
// ...
<link href="{{ asset('bundles/ajaxflashmessage/css/flash-message.css') }}" type="text/css" rel="stylesheet" />
{% endblock %}
Add this call to a script block in your layout or to some of your templates:
<script>
$('#flash-messages').flashNotification('init');
</script>