Lightweight, simple and easy way to display flash message with Bootstrap 5 (Alert) template
Lightweight, simple and easy way to display flash message with Bootstrap 5 (Alert) template
composer require elmyrockers/ezflash
require_once 'vendor/autoload.php'; //Load Composer's autoloader
use elmyrockers\EzFlash;
$message = new EzFlash;
After that, you can set flash message in 4 different ways:
$message->{$key} = {$yourmessage};
$message->success = 'Message'; //Property
$message['success'] = 'Message'; //Array key
$message->success( 'Message' ); //Method call or
$message( 'success', 'Message' ); //Function call
echo $message(); //Function call with no parameter
Or you can treat this object like a string:
echo $message;
For instance, if you write code like the following statement:
$message( 'success', 'My message' ); //Set flash message through function call
echo $message; // Echo flash message (one-time display)
Then, its output will look like this one:
<div class="alert alert-success">My message</div>
$message->setTemplate( ['success',
'danger',
'warning',
'info',
'primary',
'secondary',
'light',
'dark',
'default'], '<div class="alert alert-{$key}">{$message}</div>' ); //default
//custom template
$message->setTemplate( 'errorInfo', '<div class="alert alert-danger {$key}">{$message}</div>' );
You can override default/existing template too with this.