CButtonColumn and YII_CSRF_TOKEN

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

http://code.google.com/p/yii/issues/detail?id=861

This issue was fixed in Yii 1.1.1

My quick fix (for earler version):

  1. Override class CButtonColumn (put class ButtonColumn in components for example);

  2. 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;