martynbiz/php-flash-message

Flash messenger that will keep messages until they are "flushed" - current or persistant states.

1.0.0 2016-01-21 12:37 UTC

This package is not auto-updated.

Last update: 2024-05-03 15:54:37 UTC


README

Flash messenger that will keep messages until they are "flushed" - current or persistant states.

Installation

Composer

"require-dev": {
    "martynbiz/php-flash-message": "dev-master"
}

Usage

Add message

$flash = new \MartynBiz\FlashMessage\Flash;
$flash->addMessage('success', 'You have successfully registered');

Check if message exists by key

$flash->has('success'); // true
$flash->has('errors'); // false

Flush messages

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.

$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:

$container = new Zend\Session\Container('mycontainer');
$flash = new Flash($container);

TODO

  • create a simple session storage as default