Download the PHP package mzur/kirby-flash without Composer
On this page you can find all versions of the php package mzur/kirby-flash. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package kirby-flash
Kirby Flash
This is a fork of jevets\kirby-flash.
Allows you to "flash" data to the session, which will be available via the session on the next page load, after which the data is removed from the session.
Very useful for:
- Saving submitted form data for form validation, specifically for the Post/Redirect/Get design pattern
- Displaying Success or Error messages after a page reload
Quick Example
Elsewhere...
Installation
Install with composer:
Usage
Set data
Get data
Examples
flash()
Helper Function
This class loads a global helper function: flash($key, $value = '')
.
The flash()
function is only defined if it doesn't already exist, so you could define your own flash()
function if necessary. Most of the time, you'll probably just use flash()
in your application.
When called with one parameter, the value is returned. If the key doesn't exist, then you'll get back an empty string.
When called with two parameters, the $value
is set for the $key
.
If $key
already exists, $value
will replace the existing $key
's value.
You may store any kind of data you want in the session. As another example, you could store multiple form validation error messages as an array in a single key.
Flash for current page load only
Sometimes it can be useful to flash a message for the current page load, not the next one. This use case arises when a message should be shown in a response to the same request, rather than a redirect.
The flash()
helper method can be called with an optional third parameter, a boolean to toggle whether to keep the flashed variable only for the current request. The default value of this parameter is false
which will keep the flashed variable for the next request.
php Jevets\Kirby\Flash::setSessionKey('_my_custom_key');
### Getting the Session Key
## Contributing
Feel free to send a pull request!
## Issues/Bugs
Please use the [GitHub issue tracker](https://github.com/mzur/kirby-flash/issues).