Difference between #3 and #4 of
Use kartik Growl with Yii2 flash messages

Revision #4 has been created by skworden on Mar 28, 2015, 4:16:19 PM with the memo:

checed for empty value. i uploaded this code to a shared server and it didn't like the shorthand the other way. this way works for both 5.4 and 5.5 php versions
« previous (#3)

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!
8 0
11 followers
Viewed: 49 449 times
Version: 2.0
Category: How-tos
Written by: skworden
Last updated by: skworden
Created on: Mar 12, 2015
Last updated: 9 years ago
Update Article

Revisions

View all history