Download the PHP package nassiry/flash-messages without Composer
On this page you can find all versions of the php package nassiry/flash-messages. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nassiry/flash-messages
More information about nassiry/flash-messages
Files in nassiry/flash-messages
Package flash-messages
Short Description A PHP package for handling flash messages with session storage & rendering.
License MIT
Informations about the package flash-messages
A lightweight PHP library for handling flash messages with session storage & simple HTML rendering. This package does not depend on any framework, but it can be integrated with frameworks like Laravel, Symfony, CakePHP, and CodeIgniter if needed.
Features
- Session-based flash message storage.
- Instant message rendering.
- Custom message types.
- Fully framework-agnostic.
Table Of Contents
- Installation
- Usage
- Default Usage (Display on Next Page Load)
- Current Page Usage (Display Immediately)
- Checking for Messages
- Retrieving Messages
- Rendering Messages
- Clearing Messages
- Adding Different Types of Messages
- Adding a custom type message
- Adding a custom type message
- Testing
- Prerequisites
- Running Tests
- License
- Contributing
Installation
The recommended way use Composer to install the package:
Usage
By default, the package stores messages in sessions to be displayed on the next page load.
1. Default Usage (Display on Next Page Load)
Note: Ensure that
session_start();
has been called in your script before using.2. Current Page Usage (Display Immediately)
To display a message on the current page, set the second argument to true
(default is false
):
3. Checking for Messages
You can check if there are any stored messages:
4. Retrieving Messages
You can retrieve all stored messages as an array:
5. Rendering Messages
Outputs all flash messages with default HTML structure
6. Clearing Messages
To clear all stored messages:
Adding Different Types of Messages
Currently, the package support following message types.
$flash->success('Success message!');
$flash->error('Error message!');
$flash->info('Informational message!');
$flash->warning('Warning message!');
Adding a custom type message
addCustomType(string $type, string $message, bool $instant = false)
Custom Rendering Logic
If you need to customize the way messages are displayed, extend the FlashMessageRenderer
class:
Testing
Run the unit tests to ensure the package works as expected:
1. Prerequisites
Ensure you have all dependencies installed by running:
2. Running Tests
Execute the following command to run the test suite:
License
This package is open-source software licensed under the MIT license.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request or open an issue.