Bootstrap alert manager for PHP projects.
Add and display bootstrap alerts with relevant Font Awesome icons
- PHP >= 8.1
Use composer to add the package to your dependencies:
composer require palmtree/bootstrap-alerts
Echoing the AlertManager class will invoke __toString()
on each alert and return a concatenated string of HTML.
<?php
$alertManager = new \Palmtree\BootstrapAlerts\AlertManager();
$alertManager->addSuccess('It worked!');
$alertManager->addInfo('Did you know?');
$alertManager->addWarning('Make sure you did it right');
$alertManager->addError('Something went wrong!');
echo $alertManager;
You can also filter alerts:
<?php
$alertManager = new \Palmtree\BootstrapAlerts\AlertManager();
$alertManager->addWarning('Make sure you did it right');
$alertManager->addError('Something went wrong!');
$alertManager->addError('Another thing went wrong!');
foreach($alertManager->getAlerts('error') as $errorAlert) {
echo $errorAlert;
}
Released under the MIT license