Download the PHP package spanky/flasher without Composer
On this page you can find all versions of the php package spanky/flasher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package flasher
Flasher
A simple PHP (5.3+) package to ease the process of displaying feedback to users of your website as they interact with it.
This package comes in handy when you want to provide some feedback to the user on the next page load, after they complete certain actions on your site. For example, a messaging confirming that they have successfully signed up, or deleted their account.
Installation
The easiest and best way to install the package is via Composer. Add the package to your requirements, and .
Once the package has been installed, ensure the Composer autoloader is required before trying to use Flasher.
Usage
To get up and running, first we need to make an instance of the class.
To do so, simply call the method on the class.
If using the implementation (the default) to store messages between page loads, ensure that the session is started before initialising the package:
Setting messages
To set a message to be displayed on the next page load, call the method, passing in the content of the message.
The first parameter is the content of the message you wish to be displayed to the user. This must be either a string, or an object implementing the method.
Notice how you can specify an optional string to denote the type of message being provided as either the second parameter of the method.
If you wish, you can also add messages of a specific type in the following way:
Displaying messages
When it comes to actually displaying the messages to the user, there are a few methods to help you do this with the most flexibility.
First, we check if there are any messages to display using the method, which returns either or depending on whether or not there are messages to show.
If there are messages, then we retrieve them by calling the method, which returns an instance of , containing objects representing the messages.
The type of a message can be retrieved by calling the method on the object, and the actual content by calling the method, or casting the object to a string.
Displaying only messages of a certain type
To only check for, or display, messages of a certain type, pass the type string into the and methods, like so:
Displaying only the first, or last message
In some instances, you might not want to display all the messages, but just the first, or last. You can do this easily, by using the or methods on the class.
Using with Laravel
If you're using this package with Laravel, then you can take advantage of the provided service provider and facade to skip the bootstrapping.
First, add to the list of in your file.
Next, add the following key/value pair to the list of in the same file.
You are now free to use the package by statically calling method names of the class on the "facade" class:
Tests
Run to trigger the test suite.