lexand
(Dorogikh Alexander)
1
Hi there
How to add YII_CSRF_TOKEN to the delete button?
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'name',
'count',
array(
'class'=>'CButtonColumn',
//something like
//'YII_CSRF_TOKEN' => 'blah_blah_blah'
),
),
)); ?>
thanks
lexand
(Dorogikh Alexander)
2
yugenekr
(Yugenekr)
3
This issue was fixed in Yii 1.1.1
My quick fix (for earler version):
-
Override class CButtonColumn (put class ButtonColumn in components for example);
-
In short - just need to add
data:{YII_CSRF_TOKEN:"{$this->csrf}"},
to method initDefaultButtons(), in these lines of code:
$this->buttons['delete']['click']=<<<EOD
function() {
$confirmation
$.fn.yiiGridView.update('{$this->grid->id}', {
type:'POST',
url:$(this).attr('href'),
data:{YII_CSRF_TOKEN:"{$this->csrf}"},
success:function() {
$.fn.yiiGridView.update('{$this->grid->id}');
}
});
return false;
}
EOD;
where
$this->csrf=Yii::app()->request->csrfToken;