Hi Gerhard…
Yes, problem solved. Solution is quite simple, however there are some complexities which made this actually quite difficult.
Solution
'url' => 'Yii::app()->controller->createUrl("/valuation/admin", array("q"=>$data->primaryKey))',
Step 1: Selecting the button to override
Firstly, you need to tell Yii which button to change the URL for. In my case, I want to change the view button so… the buttonId being view, I put ‘view’ into the array.
If I wanted to override the default behaviour for delete, I would put ‘delete’ into the array.
'buttons' => array(
'view' => array ( [STUFF IN HERE] ),
),
http://www.yiiframework.com/wiki/106/using-cbuttoncolumn-to-customize-buttons-in-cgridview/
Step 2: Overriding the URL
You can’t just put a createUrl in here. The problem is that the value stored by the ‘url’ key needs to be in string format. Note the speech marks.
'view' => array ( 'url' => 'Yii::app()->controller->createUrl("/valuation/admin"' ),
Step 3: Adding Dynamic Parameters to the URL
You can access the data within that particular row of the table via $data. And the primaryKey for that row is stored as $data->primaryKey.
The following code will append the following parameter to the end of the URL assuming primaryKey is 5 ‘?q=5’
array("q"=>$data->primaryKey))
Putting it all together:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'quote-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
'id',
'description',
'user_id',
'date_created',
'date_expired',
array(
'class'=>'CButtonColumn',
'buttons' => array(
'view' => array (
'url' => 'Yii::app()->controller->createUrl("/valuation/admin", array("q"=>$data->primaryKey))',
),
),
),
),
)); ?>
Problem is that when scaffolding / using things like gridviews, everything is very much hidden away.
Took me hours to find out how to find one line of code example in documentation below:
Using CButtonColumn to customize buttons in CGridView
'url'=>'Yii::app()->createUrl("users/email", array("id"=>$data->id))'
Customising a gridview buttoncolumn parameter should be common practice. I feel really gutted with such a great framework such as Yii in that:
[list=1]
[*]It is not obvious how to do this
[*]No real examples to help us along
[*]I had absolutely no help on forums
[*]Finding out how to do something so simple took hours!
[/list]