Some problem with 'buttons' ('url') in CGridView

Hi all

I need to use my action for delete lines in table instead of default actionDelete.

actionUserDelete:




class AdminController extends CController {

.......    

    public function actionUserDelete($id) {

        if (!empty($id))

            Admin::model()->deleteByPk($id);

			

        $this->redirect($this->createUrl('user'));

        return;

    }

.......



and views/admin/user.php


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

	'dataProvider'=>$dataProvider,

	'columns' => array(

		'name',

		'password',

		array(

			'class' => 'CButtonColumn',

			'template' => '{delete}',

		        

                        'buttons' => array(

				'delete' => array(

				    'url' => 'Yii::app()->createUrl("admin/userDelete", array("id"=>$data->id))',	

				),                        

                        ),

	        ),

	));

?>

But it doesn’t work. I see only blank page without any content. Tried to comment section ‘buttons’ in view and it almost worked(exclude delete button).

Can smb explain me how to fix it?

If you want to set another URL for the default ‘delete’ button… use deleteButtonUrl - http://www.yiiframework.com/doc/api/1.1/CButtonColumn#deleteButtonUrl-detail

mdomba, thanks for useful man, but the problem was in unclosed bracket at the end of grid widget >_< (I killed few days for searching solution).

think this topic can be closed/deleted

No need to close it or delete… it will be good for other users if they will have similar problem…

What about if I want to trigger some javascript unstead of redirect to and url




'class'=>'CButtonColumn',

'template' => '{view} {delete}',            

'buttons' => array(  

    'view' => array( 

       'url' => 'SOME JAVASCRIPT ACTION',        

    ), 

    'delete' => array( 

        'url' => 'Yii::app()->createUrl("admin/userDelete", array("id"=>$data->id))',        

    ),                         

),



any idea?

I think I got it





'view' => array( 

    'url' => 'Yii::app()->createUrl("admin/userView", array("id"=>$data->id))',

    'click' => 'function() {

          alert(\'Hello world\'); 

	  return false

        }',



You’d do something like this:


'buttons'=>array(

	'view'=>array(

		'url'=>'#',

		'options'=>array(

			'onclick'=>'alert("javascript");',

		),

	),

),