Hi,
I was trying to create a custom button which will modify database. I was using cgridview and created custom button. However, when I click the button, the database does get modified but the request is a normal post request and not an ajax request…
here’s what I;m doing
View
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'id' => 'my-grid',
'dataProvider'=>$dataProvider,
'columns'=>array(
'id',
'username',
'firstName',
'lastName',
'role',
array(
'header' => '',
'class' => 'CButtonColumn',
'template'=>'{status}',
‘buttons’=>array
(
'status' => array
(
'click'=>"function(){
$.fn.yiiGridView.update('my-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(data) {
$('#AjFlash').html(data).fadeIn().animate({opacity: 1.0}, 3000).fadeOut('slow');
$.fn.yiiGridView.update('my-grid');
}
})
return false;
}
",
'url'=>'Yii::app()->controller->createUrl("status",array("id"=>$data->id))',
)) ,
),),
)); ?>
<div id=‘AjFlash’ class=“flash-success” style=“display:none”>Hello</div>
On clicking the button, the database get’s mofified and my grid gets updated with the value but the flash message is not displayed
here is my controller
public function actionStatus($id)
{
$model=member::model()->findByPk($id);
$model->firstName='Test2';
$model->save();
if(!isset($_GET['ajax']))
$this->redirect(Yii::app()->request->urlReferrer);
}
If I do not check for isset($_GET[‘ajax’]), I’m not returned back to my view which means that this request is not ajax right? and if it is why is my flash message not displaying?
Any help would be appreciated…
Rgds
vv