<?php
//form
class SomeForm extends CFormModel
{
public $id;
public $user_id;
public function search()
{
$sql = 'SELECT id, name FROM some_table';
$sql_count = 'SELECT COUNT(id) FROM some_table';
return new CSqlDataProvider($sql, array(
'totalItemCount' => Yii::app()->db->createCommand($sql_count)->queryScalar(),
'sort' => array(
'attributes' => array(
'id', 'name',
),
),
'pagination' => array(
'pageSize' => 50,
),
));
}
public function attributeLabels()
{
return array(
'id' => 'ID',
'name' => 'NAME',
);
}
}
//grid
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(), //$model = new SomeForm()
'columns' => array(
'id',
'name'
),
));
/*
Result:
id | name
---------
1 | John
EXPECTED Result:
ID | NAME
---------
1 | John
*/
如何为查询列设置自定义名称?