Download the PHP package williamsampaio/slim-flash-messages without Composer
On this page you can find all versions of the php package williamsampaio/slim-flash-messages. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download williamsampaio/slim-flash-messages
More information about williamsampaio/slim-flash-messages
Files in williamsampaio/slim-flash-messages
Package slim-flash-messages
Short Description Slim Framework Flash message service provider
License MIT
Homepage https://github.com/WilliamSampaio/Slim-Flash-Messages
Informations about the package slim-flash-messages
Slim Flash Messages
This library allows you to use temporary messages in your Slim project. It is easily integrated with the Twig template system, through an extension that provides functions to grab and use in the template. It is not limited to creating simple message strings but also allows the use of other data types such as arrays.
Install
Usage Examples (Slim 4)
Simplest possible
Twig integration is not mandatory, as you can see in this example, where the focus is on demonstrating the messaging provider API.
With Container
This example uses the php-di container and slim/twig-view.
In template:
Running these examples
The easiest way to run these examples is through docker.
When you complete the up process, access:
- Example 1: http://localhost:8080/example1/
- Example 2: http://localhost:8080/example2/
- Code Coverage: http://localhost:8080/coverage/index.html
Custom Twig Functions
FlashTwigExtension
provides these functions to your Twig templates.
flash()
It receives two optional parameters, key
*(string/null = null) and clear
(bool = true)*.
key
: If is not specified, an array with all the data in storage will be returned, otherwise only the array with the data indexed by the key value will be returned.clear
: If is false, the items will not be removed from storage after the function is called.
flash_first()
It receives two parameters, key
(string) and remove
*(bool = true)*.
key
: First item from array with the data indexed by the key value will be returned.remove
(optional): If is false, the item will not be removed from storage after the function is called.
flash_last()
It receives two parameters, key
(string) and remove
*(bool = true)*.
key
: Last item from array with the data indexed by the key value will be returned.remove
(optional): If is false, the item will not be removed from storage after the function is called.
flash_has()
It receives one parameters, key
(string). Checks if a key is defined in the storage. Return true
or false
.
key
: The key that will be checked.
flash_clear()
It receives one optional parameters, key
(string). Removes data from storage. Return void
.
key
(optional): The key that will be removed. If not defined, it removes all data from the storage.
Tests
To execute the test suite, you'll need to clone the repository and install the dependencies.
License
The MIT License (MIT). Please see License File for more information.