I'm showing a CGridView for another related model in view&id=n
page. The necessary relations are included in model files and everything works just fine. The only thing is that the buttons in the CButtonColumn
are linked to the appropriate actions of the model which page is being opened, while I want them to link to the actions of the related model.
To explain clear what I mean, here is my code. In view.php
of Order
model:
$dataProvider=new CActiveDataProvider('OrderContents', array(
'criteria'=>array(
'condition'=>'order_id='.$model->id,
'with'=>array('order'),
),
'pagination'=>array(
'pageSize'=>20,
),
));
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'orders-contents-grid',
'dataProvider'=>$dataProvider,
'columns'=>array(
'id',
'comp_name',
'quantity',
'comment',
array(
'class'=>'CButtonColumn',
),
),
));
Thus, I want the buttons in CButtonColumn
to link to the appropriate actions for OrderContents
model, while there are now linked to the actions of Order
model. Is there any easy way to achieve this? I checked the API for both CButtonColumn
and CGridView
to see if I can get any inspiration there but had no luck.
Actually, you don't even need to create a custom button if all you want to do is change the urls. Look at viewButtonUrl
, updateButtonUrl
and deleteButtonUrl
for CButtonColumn.
You'd adjust the urls as shown the other answer