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.

43 lines
1003 B

7 years ago
<?php
namespace frontend\widgets;
use Yii;
use yii\base\Widget;
class Alert extends Widget
{
public $alertTypes = [
'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;
}
foreach ((array) $flash as $i => $message) {
$html = <<<HTML
<div class="alert {$this->alertTypes[$type]} alert-dismissible fade show" role="alert">
{$message}
<!--<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>-->
</div>
HTML;
echo $html;
}
$session->removeFlash($type);
}
}
}