123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app\widgets;
- use Yii;
- class Alert extends \yii\bootstrap\Widget
- {
-
- public $alertTypes = [
- 'error' => 'alert-danger',
- 'danger' => 'alert-danger',
- 'success' => 'alert-success',
- 'info' => 'alert-info',
- 'warning' => 'alert-warning'
- ];
-
- public $closeButton = [];
-
- public function run()
- {
- $session = Yii::$app->session;
- $flashes = $session->getAllFlashes();
- $appendClass = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
- foreach ($flashes as $type => $flash) {
- if (!isset($this->alertTypes[$type])) {
- continue;
- }
- foreach ((array) $flash as $i => $message) {
- echo \yii\bootstrap\Alert::widget([
- 'body' => $message,
- 'closeButton' => $this->closeButton,
- 'options' => array_merge($this->options, [
- 'id' => $this->getId() . '-' . $type . '-' . $i,
- 'class' => $this->alertTypes[$type] . $appendClass,
- ]),
- ]);
- }
- $session->removeFlash($type);
- }
- }
- }
|