https://github.com/benanamen/perfect-flash-bs-5
Bootstrap5FlashMessage is a PHP class that provides a simple and effective way to display flash messages in a web application. It uses Bootstrap 5 for styling and allows for optional icons and dismissible alerts.
https://github.com/benanamen/perfect-flash-bs-5
bootstrap flash-messages php8
Last synced: 3 months ago
JSON representation
Bootstrap5FlashMessage is a PHP class that provides a simple and effective way to display flash messages in a web application. It uses Bootstrap 5 for styling and allows for optional icons and dismissible alerts.
- Host: GitHub
- URL: https://github.com/benanamen/perfect-flash-bs-5
- Owner: benanamen
- License: mit
- Created: 2023-10-09T22:35:07.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-10T01:56:24.000Z (over 2 years ago)
- Last Synced: 2025-10-19T17:59:14.664Z (8 months ago)
- Topics: bootstrap, flash-messages, php8
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://codecov.io/gh/benanamen/perfect-flash-bs-5)
[](https://scrutinizer-ci.com/g/benanamen/perfect-flash-bs-5/?branch=master)
[](https://scrutinizer-ci.com/g/benanamen/perfect-flash-bs-5/?branch=master)
[](https://scrutinizer-ci.com/g/benanamen/perfect-flash-bs-5/build-status/master)
[](https://scrutinizer-ci.com/code-intelligence)
[](https://sonarcloud.io/summary/new_code?id=benanamen_perfect-flash-bs-5)
[](https://sonarcloud.io/summary/new_code?id=benanamen_perfect-flash-bs-5)
[](https://sonarcloud.io/summary/new_code?id=benanamen_perfect-flash-bs-5)
[](https://sonarcloud.io/summary/new_code?id=benanamen_perfect-flash-bs-5)
[](https://sonarcloud.io/summary/new_code?id=benanamen_perfect-flash-bs-5)
[](https://sonarcloud.io/summary/new_code?id=benanamen_perfect-flash-bs-5)
[](https://sonarcloud.io/summary/new_code?id=benanamen_perfect-flash-bs-5)
[](https://sonarcloud.io/summary/new_code?id=benanamen_perfect-flash-bs-5)
[](https://sonarcloud.io/summary/new_code?id=benanamen_perfect-flash-bs-5)
[](https://sonarcloud.io/summary/new_code?id=benanamen_perfect-flash-bs-5)
# Bootstrap5FlashMessage
## Description
`Bootstrap5FlashMessage` is a PHP class that provides a simple and effective way to display flash messages in a web application. It uses Bootstrap 5 for styling and allows for optional icons and dismissible alerts.
## Requirements
- PHP 8.0 or higher
- Bootstrap 5.3 or higher
## Installation
Include the `Bootstrap5FlashMessage` class in your project.
## Usage
### Initialization
First, you need to inject a session object that implements `SessionInterface` and an array of messages into the constructor.
```php
use PerfectApp\Session\SessionInterface;
use PerfectApp\Bootstrap5FlashMessage;
$session = new Session(); // This should implement SessionInterface
$messages = [
'success' => [
'insert' => 'Record Inserted'
],
'danger' => [
'failed_login' => 'Invalid Login'
]
];
$flash = new Bootstrap5FlashMessage($session, $messages);
```
### Adding a Message
To add a flash message, use the `addMessage` method.
```php
$flash->addMessage('success', 'insert');
```
You can also add an optional icon and make the alert dismissible.
```php
$flash->addMessage('danger', 'failed_login', 'bi-x-circle', true);
```
### Displaying Messages
To display all the flash messages, use the `displayMessages` method.
```php
$flash->displayMessages();
```
This will output Bootstrap 5 styled alerts.
## Testing
Run the following command to execute the unit tests and ensure 100% code coverage:
```bash
php vendor/bin/codecept run --coverage --coverage-html --coverage-xml
```
## License
This project is licensed under the MIT License.