calgus / flash
Flash messages in session designed for Anax-MVC.
Requires
- php: >=5.4
This package is not auto-updated.
Last update: 2025-04-02 12:53:34 UTC
README
Saves messages in session and pulls them from session to be displayed. Used in conjunction with Anax-MVC
Installation
Install using Packagist or clone code from Github source:
"calgus/flash": "dev-master"
Add following text to apply flash in DI in your Anax MVC framework:
$di->set('flash', function() use ($di) {
$flash = new \Anax\FlashMessages\CFlashBasic();
$flash->setDI($di);
return $flash;
});
Add following text to apply Flash Controller in DI in your Anax MVC framework:
$di->set('FlashController', function() use ($di) {
$flashController = new \Anax\FlashMessages\FlashController();
$flashController->setDI($di);
return $flashController;
});
Flash Controller is only used as an example to display post flash messages and is not needed for module use. Use
$messages = $this->flash->getSessionMessageClean();
foreach ($messages as $index => $value) {
$type = $value['type'];
$message = $value['message'];
}
to access the session name yourself.
These are optional commands to use when you want to save a message or display messages.
To save messages in session - Error message:
$app->flash->errorMessage('Error message');
Success message:
$app->flash->successMessage('Success message');
Notice message:
$app->flash->noticeMessage('Notice message');
Warning message:
$app->flash->warningMessage('Warning message');
To get the messages either use - Get clean array with all messages stored in session:
$app->flash->getSessionMessageClean();
Get p tags with messages type and containing messages:
$app->flash->getSessionMessage();
Use $this instead of $app while inside DI classes and apps.
Detailed instructions.
- Copy flash-messages.php from webroot to your webroot folder.
- Copy src/FlashMessages folder to your src folder.
- Copy app/view/flash to your app/view folder.
- Copy webroot/css/flash.css to your webroot/css folder.
- Open flash-messages.php file in browser and enjoy.