Changes
Title
unchanged
Use kartik Growl with Yii2 flash messages
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
kartik-v, kartik, alert, flash message, session, yii2, lifedup
Content
changed
[...]
use Yii;
use yii\helpers\Html;
//Get all flash messages and loop through them
<?php foreach (Yii::$app->session->getAllFlashes() as $message):; ?>
<?php
<?php
echo \kartik\widgets\Growl::widget([
'type' =>
(!empty($message['type'])
) ? $message['type'] : 'danger',
'title' =>
(!empty($message['title'])
) ?
Html::encode($message['title']
) : 'Title Not Set!',
'icon' =>
(!empty($message['icon'])
) ? $message['icon'] : 'fa fa-info',
'body' =>
(!empty($message['message'])
) ?
Html::encode($message['message']
) : 'Message Not Set!',
'showSeparator' => true,
'delay' => 1,
//This delay is how long before the message shows
'pluginOptions' => [
'delay' =>
(!empty($message['duration'])
) ? $message['duration'] : 3000,
//This delay is how long the message shows for
'placement' => [
'from' =>
(!empty($message['positonY'])
) ? $message['positonY'] : 'top',
'align' =>
(!empty($message['positonX'])
) ? $message['positonX'] : 'right',
]
]
]);
?>
]
]);
?>
<?php endforeach; ?>
```
If you get any class not found errors please ensure you are using the proper "use" statements in your files at the top!
That’s all you have to do, enjoy!