|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?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);
- }
- }
- }
- }
|