-
Notifications
You must be signed in to change notification settings - Fork 11
/
ToastrFlash.php
58 lines (50 loc) · 1.41 KB
/
ToastrFlash.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
<?php
/**
* @copyright Copyright © Odai Alali 2014
* @package yii2-toastr
* @version 0.1-dev
*/
namespace odaialali\yii2toastr;
use odaialali\yii2toastr\Toastr;
/**
* Description of ToastrFlash
*
* @author Odai Alali <[email protected]>
*/
class ToastrFlash extends \yii\base\Widget {
/*
* @var boolean use custom style in asset ToastrCustomAsset
*/
public $customStyle = true;
/**
* @var array the alert types configuration for the flash messages.
*/
public $alertTypes = [
'error' => 'error',
'danger' => 'error',
'success' => 'success',
'info' => 'info',
'warning' => 'warning'
];
public $options = [];
public function init()
{
parent::init();
$session = \Yii::$app->getSession();
$flashes = $session->getAllFlashes();
foreach ($flashes as $type => $data) {
if (isset($this->alertTypes[$type])) {
$data = (array) $data;
foreach ($data as $message) {
echo Toastr::widget([
'toastType' => $this->alertTypes[$type],
'message' => $message,
'options' => $this->options,
'customStyle' => $this->customStyle
]);
}
$session->removeFlash($type);
}
}
}
}