edinchev / flash-alert-bundle
FlashAlertBundle provides a simplified way to handle (add/display) Symfony flash messages. Client side scripts are written in pure JavaScript.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 3 210
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 9
Forks: 8
Type:symfony-bundle
Requires
- php: >=5.3.3
- symfony/symfony: >=2.1
- twig/twig: ~1.12
This package is not auto-updated.
Last update: 2019-03-17 04:02:40 UTC
README
FlashAlertBundle is an open source Bundle which simplifies displaying flash alerts such as success, error, info and warning
Note: This was forked because the main repo seemed to no longer be maintained and there was a bug in migrating to Symfony 3.3. I will maintain this repo and review pull requests.
Table of Contents
- Installation
- Download the FlashAlertBundle
- Enable the bundle
- Configure the bundle
- Usage
- Report flash alerts
- Display flash alerts
- Configuration
- Override view template
- Add custom styles
- Changelog
- License
Installation
Step 1: Download the FlashAlertBundle
Using Composer Run the following command using composer:
composer require edinchev/flash-alert-bundle
OR add the following to the "require" section of your composer.json
file:
"edinchev/flash-alert-bundle": "^1.0.0"
Step 2: Enable the bundle
Registers the bundle in your app/AppKernel.php
:
<?php ... public function registerBundles() { $bundles = array( ... new Ras\Bundle\FlashAlertBundle\RasFlashAlertBundle(), ... ); ...
Step Optional, if you are not using composer: Configure the Autoloader
Add the following to your autoload.php
:
<?php ... 'Ras' => __DIR__.'/../vendor/bundles',
Usage
Report flash alerts
Add the following PHP code to report an alert message:
$this->get('ras_flash_alert.alert_reporter')->addError("Access denied");
Note: You can choose one of the following functions to call from
$this->get('ras_flash_alert.alert_reporter')
addSuccess()
addError()
addWarning()
addInfo()
Display flash alerts
Add the following twig code where you want to display alert messages:
{{ render_flash_alerts() }}
Note 1: The parent twig template would be the best place for displaying flash alerts
Configuration
The following parameters can be overriden in your config.yml
or similar:
ras_flash_alert:
template: '::flashAlerts.html.twig' # defaults to 'RasFlashAlertBundle::layout.html.twig'
isAddStyles: false # defaults to true
isAddJsAlertClose: false # defaults to true
These can also be passed as parameters in the view when rendering alerts - for example:
{{ render_flash_alerts({ 'template': '::flashAlerts.html.twig', 'isAddStyles': false }) }}
Override view template
- Create template in the
/Resources/views/
or in your bundle - Retrieve alerts into your template with
{{ get_alert_publisher() }}
- Include template blocks in
FlashAlertBundle/Resources/views/FlashAlert
directory or define your own blocks (followFlashAlertBundle/Resources/views/FlashAlert/flashAlerts.html.twig
to see how you can define your own template)
Add custom styles
The bundle default template has styles defined by default. However, you can turn off default styles by configuring isAddStyles variable to false as shown in below.
{{ render_flash_alerts({ 'isAddStyles': false }) }}
Then you can define your own styles to match alert classes such as alert
,
alert-close
, alert-success
, alert-error
, alert-warning
and alert-info
LICENSE
FlashAlertBundle is licensed under the MIT Open Source license.