Flash
Flash messenger that will keep messages until they are \"flushed\" - current or persistant states., (*1)
Installation
Composer, (*2)
"require-dev": {
"martynbiz/php-flash-message": "dev-master"
}
Usage
Add message, (*3)
$flash = new \MartynBiz\FlashMessage\Flash;
$flash->addMessage('success', 'You have successfully registered');
Check if message exists by key, (*4)
$flash->has('success'); // true
$flash->has('errors'); // false
Flush messages, (*5)
This method can be called during the same HTTP request or future request. This means
it is useful when redirecting but also forwarding to, for example, another controller
action. The contents of the container will be emptied when this method is called once., (*6)
$messages = $flash->flushMessages();
Using custom storage
It is possible to use your own storage object, as long as it implements ArrayAccess
interface. Below Zend\Storage\Container has been used:, (*7)
$container = new Zend\Session\Container('mycontainer');
$flash = new Flash($container);
TODO, (*8)
- create a simple session storage as default