-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAlert.php
65 lines (53 loc) · 1.92 KB
/
Alert.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
<?php
namespace yiichina\adminlte;
use Yii;
class Alert extends \yii\bootstrap\Widget
{
public $alertTypes = [
'error' => [
'class' => 'alert-danger',
'icon' => '<i class="icon fa fa-ban"></i>',
],
'danger' => [
'class' => 'alert-danger',
'icon' => '<i class="icon fa fa-ban"></i>',
],
'success' => [
'class' => 'alert-success',
'icon' => '<i class="icon fa fa-check"></i>',
],
'info' => [
'class' => 'alert-info',
'icon' => '<i class="icon fa fa-info"></i>',
],
'warning' => [
'class' => 'alert-warning',
'icon' => '<i class="icon fa fa-warning"></i>',
],
];
public $closeButton = [];
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) {
/* initialize css class for each alert box */
$this->options['class'] = $this->alertTypes[$type]['class'] . $appendCss;
/* assign unique id to each alert box */
$this->options['id'] = $this->getId() . '-' . $type . '-' . $i;
echo \yii\bootstrap\Alert::widget([
'body' => $this->alertTypes[$type]['icon'] . $message,
'closeButton' => $this->closeButton,
'options' => $this->options,
]);
}
$session->removeFlash($type);
}
}
}
}