You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
861 B

7 years ago
<?php
namespace frontend\widgets;
use Yii;
use yii\base\Widget;
class Alert extends Widget
{
3 years ago
public array $alertTypes = [
7 years ago
'error' => 'alert-danger',
'danger' => 'alert-danger',
'success' => 'alert-success',
'info' => 'alert-info',
'warning' => 'alert-warning'
];
public function run()
{
$session = Yii::$app->session;
$flashes = $session->getAllFlashes();
foreach ($flashes as $type => $flash) {
if (!isset($this->alertTypes[$type])) {
continue;
}
3 years ago
foreach ((array) $flash as $message) {
7 years ago
$html = <<<HTML
<div class="alert {$this->alertTypes[$type]} alert-dismissible fade show" role="alert">
{$message}
</div>
HTML;
echo $html;
}
$session->removeFlash($type);
}
}
}