https://github.com/co0lc0der/flash-component
Flash messages php component
https://github.com/co0lc0der/flash-component
flash-messages php php-oop
Last synced: 7 months ago
JSON representation
Flash messages php component
- Host: GitHub
- URL: https://github.com/co0lc0der/flash-component
- Owner: co0lc0der
- Created: 2021-04-05T08:02:29.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-05T19:17:08.000Z (almost 5 years ago)
- Last Synced: 2025-01-13T13:48:58.833Z (about 1 year ago)
- Topics: flash-messages, php, php-oop
- Language: PHP
- Homepage:
- Size: 1.95 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flash messages php component
This is an easy-to-use php component for working with flash messages in your project. It uses `$_SESSION` to store messages. Because of it you have to use `session_start()` at the begining of your script. See `index.php` for example.
### Public methods:
- `exists()` - check existing a message by its type
- `setFlash()` - set a flash message
- `getFlash()` - return the added message
## How to use
### 1. Include the Flash class.
```php
include __DIR__ . '/Flash/Flash.php';
```
### 2. Add a flash message by method `setFlash()`. Type 'danger' is by default.
```php
Flash::setFlash('Error message.');
Flash::setFlash('Some information.', 'info');
Flash::setFlash('Job is done!', 'success');
Flash::setFlash('Additional error message.', 'danger', false);
```
### 3. To print the added message use `getFlash()` method.
```php
echo Flash::getFlash('info');
echo Flash::getFlash('danger');
echo Flash::getFlash('success');
```