|
- <?php
-
-
- namespace frontend\widgets;
-
-
- 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 init()
- {
- parent::init();
-
- $session = \Yii::$app->getSession();
- $flashes = $session->getAllFlashes();
- $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
-
- foreach ($flashes as $type => $data) {
- if (isset($this->alertTypes[$type])) {
- $data = (array) $data;
- foreach ($data as $i => $message) {
-
- $this->options['class'] = $this->alertTypes[$type] . $appendCss;
-
-
- $this->options['id'] = $this->getId() . '-' . $type . '-' . $i;
-
- echo \yii\bootstrap\Alert::widget([
- 'body' => $message,
- 'closeButton' => $this->closeButton,
- 'options' => $this->options,
- ]);
- }
-
- $session->removeFlash($type);
- }
- }
- }
- }
|