ajur-media / template.flash
Flash messages based on Slim Framework code
0.99.0
2024-08-29 17:00 UTC
Requires
- php: ^7.4 || 8.*
Requires (Dev)
- phpunit/phpunit: ^4.0
- rector/rector: ^0.19.8
This package is not auto-updated.
Last update: 2025-01-02 18:41:47 UTC
README
Flash messages enables you to define transient messages that persist only from the current request to the next request.
Install
Via Composer
$ composer require ajur-media/template.flash
Usage
Slim 3
// Start PHP session if (!session_id()) @session_start(); App::$flash = new \AJUR\Template\FlashMessages(); // or use DI Container $app->get('/foo', function ($req, $res, $args) { // Set flash message for next request App::$flash->addMessage('Test', 'This is a message'); // Redirect return $res->withStatus(302)->withHeader('Location', '/bar'); }); $app->get('/bar', function ($req, $res, $args) { // Get flash messages from previous request $messages = $this->flash->getMessages(); print_r($messages); // Get the first message from a specific key $test = $this->flash->getFirstMessage('Test'); print_r($test); }); $app->run();
Please note that a message could be a string, object or array. Please check what your storage can handle.
Testing
$ phpunit
License
The MIT License (MIT). Please see License File for more information.