notifyii with yii flash messages

sensorario edited this page Oct 20, 2012 · 1 revision
Clone this wiki locally

First of all, you need to read how to work with flash messages and then you can understand yii flash messages for notifyii.

First of all, you need to load notifications and save them into a flash message:

class SomeController extends Controller
    public function actionIndex() {
        $notifiche = ModelNotifyii::getAllNotifications();
        foreach ($notifiche as $notifica) {
            if($notifica->isNotReaded()) {
                Yii::app()->user->setFlash('success', $notifica->content);

Second, you must show in your view flash messages:

<?php foreach(Yii::app()->user->getFlashes() as $key => $message) : ?>
    <?php echo '<div class="flash-' . $key . ' info">' . $message . "</div>\n"; ?>
<?php endforeach; ?>

Last, but not least, you can auto-hide flash messages

<?php Yii::app()->clientScript->registerScript(
    '$(".info").animate({opacity: 1.0}, 3000).fadeOut("slow");',
); ?>