Difference between #3 and #4 of
How to show ajax delete status in CGridView like flash messages

Revision #4 has been created by Artur Oliveira on Jun 9, 2011, 6:43:31 PM with the memo:

Added getFlash in view, Added some verifications in controller to check if ajax request
« previous (#3) next (#5) »


Title unchanged

How to show ajax delete status in CGridView like flash messages

Category unchanged


Yii version unchanged

Tags unchanged

CGridView, Ajax flash message, ajax request, Delete Status

Content changed

Yii::app()->user->setFlash('deleteStatus','success','Normal - Deleted Successfully');     else
echo "<div class='flash-success'>Ajax - Deleted Successfully</div>"; //for ajax }catch(CDbException $e){     if(!isset($_GET['ajax']))
Yii::app()->user->setFlash('deleteStatus','error','Normal - error message');     else
echo "<div class='flash-error'>Ajax - error message</div>"; //for ajax

// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

And in your
 admin (or other where you have the {delete} in GridView) view, show the echoed message in the statusMsg place holder using data variable. ```php <spandiv id='"statusMsg'></span">
<?php if(Yii::app()->user->hasFlash('success')):?>
    <div class="flash-success">
        <?php echo Yii::app()->user->getFlash('success'); ?>
<?php endif; ?>
<?php if(Yii::app()->user->hasFlash('error')):?>
    <div class="flash-error">
        <?php echo Yii::app()->user->getFlash('error'); ?>
<?php endif; ?>
<?php $this->widget('zii.widgets.grid.CGridView', array(

This way everything works even if you disable ajax requests in GridView using:
$this->widget('zii.widgets.grid.CGridView', array(
Hope this will be helpful.
17 0
Viewed: 48 140 times
Version: 1.1
Category: How-tos
Written by: hasanavi
Last updated by: adlersd
Created on: Jun 8, 2011
Last updated: 5 years ago
Update Article


View all history