In this tip, I'll help you to change in few second buttons of your CGridView. I hope you like it =).
This is our standard grid created by yii (with gii, or console, ...)
$this->widget('zii.widgets.grid.CGridView', array( 'id' => 'standard-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array( 'id', 'field', array( 'class' => 'CButtonColumn', ), ), ));
What if we want to easy upgrade columns of all our grid? we can extend CButtonColumn with a new class. We can create this class and call it MyCButtonColumn (for example). Then change column class in our CGridView:
$this->widget('zii.widgets.grid.CGridView', array( 'id' => 'standard-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array( 'id', 'field', array( 'class' => 'MyCButtonColumn', ), ), ));
Second, create MyCButtonColumn class in /protected/components/MyCButtonColumn.php
class MyCButtonColumn extends CButtonColumn { public $template = '{update} {delete}'; }
In this example, we simply replace standard template deleting '{view}' button.