romanato / php-flashingo-messages
Session based flash messages for PHP.
Requires
- php: ^7.2
This package is auto-updated.
Last update: 2024-04-25 05:44:34 UTC
README
Session based flash messages for PHP.
Flash messages are optimized to work with Bootstrap.
Installation
composer require romanato/php-flashingo-messages
Usage
// Create new instance $flashingo = new Romanato\FlashingoMessage\FlashingoMessage; // Set flash message $flashingo->set('This is a flash message.'); // Display messages $flashingo->displayAll();
Advanced usage
// Set type using set method $flashingo->set('This is a flash error message.', 'error'); // Set type using shorter method $flashingo->setWarning('This is an warning but shorter.'); // Set options $flashingo->set('I am awesome!', 'warning', [ 'name' => 'awesomeId', 'class' => 'specialClass' ]); $flashingo->setSuccess('I am awesome!', [ 'name' => 'awesomeId', 'class' => 'specialClass' ]); // Display message by name $flashingo->display('awesomeId');
Customize
Editing default css class
In FlashingoMessage.php you can add your own default class so it will fit perfectly for your project:
public $cssDefaultClass = 'myAwesomeClass';
Adding custom types
In FlashingoMessage.php you can add your own types:
public $types = [ 'default' => 'alert-primary', 'error' => 'alert-error', 'warning' => 'alert-warning', 'info' => 'alert-info', 'success' => 'alert-success', 'custom' => 'alert-custom', ];
So the generated HTML can look like this:
<div class='myAwesomeClass alert-custom' role='alert'>I am awesome!</div>
Methods
set(string
$message [, string
$type, array
$options])
This method sets a message. There are 3 parameters:
string
$message - The message that will shownstring
$type (optional) - Type of flash messagearray
$options (optional) - Sets name|class for flash message.
$flashingo->set($message, $type, [ 'class' => $class, 'name' => $name ]);
setError(string
$message [, array
$options])
This method sets an error message.
$flashingo->setError($message, [ 'class' => $class, 'name' => $name ]);
setWarning(string
$message [, array
$options])
This method sets a warning message.
$flashingo->setWarning($message, [ 'class' => $class, 'name' => $name ]);
setInfo(string
$message [, array
$options])
This method sets a info message.
$flashingo->setInfo($message, [ 'class' => $class, 'name' => $name ]);
setSuccess(string
$message [, array
$options])
This method sets a success message.
$flashingo->setSuccess($message, [ 'class' => $class, 'name' => $name ]);
setDefault(string
$message [, array
$options])
This method sets a default message.
$flashingo->setDefault($message, [ 'class' => $class, 'name' => $name ]);
display(string
$name)
This method shows a message with unique name.
$flashingo->display($name);
displayAll()
This method shows all messages.
$flashingo->displayAll();
destroyAll()
This method destroys all the session messages.
$flashingo->destroyAll();
Options
Every set()
method has the same options as a 3rd array parameter:
- name - Unique id for flash message
- class - Custom class for flash message