-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlert-old.php
66 lines (57 loc) · 1.4 KB
/
Alert-old.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Alert
*
*@package vendor.tangniyuqi.yii2-zui
*@author tangming <[email protected]>
*@copyright DNA <http://www.Noooya.com/>
*@version 1.0.0
*@since 2017-05-18 Create
*@todo N/A
*/
namespace tangniyuqi\zui;
class Alert extends \yii\bootstrap\Widget
{
/**
* @inheritdoc
*/
public $alertTypes = [
'error' => 'alert-danger',
'danger' => 'alert-danger',
'success' => 'alert-success',
'info' => 'alert-info',
'warning' => 'alert-warning',
];
/**
* @inheritdoc
*/
public $closeButton = [];
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$session = \Yii::$app->session;
$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;
if (is_array($message)) {
$message = implode($message, '<br>');
}
echo \yii\bootstrap\Alert::widget([
'body' => $message,
'closeButton' => $this->closeButton,
'options' => $this->options,
]);
}
$session->removeFlash($type);
}
}
}
}