CCheckBoxColumn and CSRF

Some time ago got the problem with CGridView and CCheckBoxColumn ajax actions with CSRF protection on.

Here is my solution also with CGridView update.

Hope the code could be useful for the others.


<?php

$this->widget('zii.widgets.grid.CGridView', array(

  'id'=>'grid_view_id',

  'dataProvider'=>$model->search(),

  'filter'=>$model,

  'columns'=>array(

       array('name'=>'user_id'),

       array(

           'class'=>'CCheckBoxColumn',

           'id'=>'check_box_id',

           'selectableRows'=>2,

       ),

   ),

));

?>


<?php

echo CHtml::ajaxLink('ClickMe',Yii::app()->createUrl('controller/action'),

  array(

    'type'=>'POST',

    'data'=>'js:{"ids" : $.fn.yiiGridView.getChecked("grid_view_id","check_box_id").toString(),"YII_CSRF_TOKEN" : "'.Yii::app()->request->csrfToken.'"}',

    'success'=>"$('#grid_view_id').yiiGridView.update('grid_view_id')"

  )

);

?>

Comments are appreciated.

Cheers.

NOTE: moved to proper section (Tips, Snippets and Tutorials instead of General Discussion for Yii 1.1.x)

Nice tip, thank you.

Ok, and thank you for the "Nice tip"