artbyrab / phlash
A very simple PHP flash messages library.
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
Requires
- php: >=5.6
Requires (Dev)
This package is auto-updated.
Last update: 2025-04-29 01:11:11 UTC
README
Phlash is a very simple PHP flash messages library. Phlash does not define how your flash messages look or whether you use javascript to close them or not. Instead, Phlash just provides the very raw tools to quickly add and get flash messages.
Requirements
- PHP 5.6+
Features
- Flash messages
- Add one or more flash messages with a type
- Define your own types like warning, info, danger or anything you desire
- Get
- Get your flash messages to show in a view
- Render any way you like including choosing your own div layouts and naming conventions
- Clear
- Clear the flash messages after they have been shown
- Add one or more flash messages with a type
Installation
The reccomended way to install is via Composer.
Ensure your minimum-stability is set to dev:
$ composer require artbyrab/phlash
or add it to your composer.json file:
"artbyrab/phlash": "master@dev"
Usage
Ensure your view or entry script has php sessions activated:
session_start();
Add one or more flash messages in your controller action or file:
use artbyrab\phlash\Phlash; Phlash::add("info", "This is Phlash!"); Phlash::add("success", "Your message was successful!"); Phlash::add("warning", "Be careful though, using Phlash can be addictive!"); Phlash::add("danger", "See it's hard to stop!");
Add a way to render the flash messages in your view/layout or file. Please note the below is just an example of how you can render your flash messages, you don't need to use the below format:
<?php if (Phlash::get() !== false) { ?> <div class="alerts"> <?php foreach (Phlash::get() as $flash) { ?> <div class="alert alert--<?=$flash->type?>"> <div class="alert__message"> <?=$flash->message?> </div> <div class="alert__close"> <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a> </div> </div> <?php }; ?> <?php Phlash::clear(); ?> </div> <?php }; ?>
For more information on using Phlash have a read of the documentation and guides: