$model= new Category();
$this->widget('zii.widgets.grid.CGridView',
array(
'id'=> 'category-grid',
'dateProvider'=> $model->search(),
'filter'=> $model,
'columns'=> array(
'title',
array(
'name'=>'create_time',
'value'=>'date("M j, Y", $data->create_time)',
),
array(
'name'=>'authorName',
'value'=>'$data->author->username',
),
array(
'class'=>'CButtonColumn',
'viewButtonUrl'=>'Yii::app()->createUrl("/trends/category/view",array("id"=>$data->id))',
'updateButtonUrl'=>'Yii::app()->createUrl("/trends/category/update",array("id"=>$data->id))',
'deleteButtonUrl'=>'Yii::app()->createUrl("/trends/category/delete",array("id"=>$data->id))',
)
)
)
);
根据字段值来显示不同内容
array(
'name'=>'id',
'type'=>'html',
'value'=>array($this, 'show')
),
回调方法 写在 控制器
/**
* 回调函数
*/
public function show($data) {
$name = $data->id==1?'<font color="red">√</font>':'<font color="blue">×</font>';
return CHtml::link($name,'');
}