摘要:本文实例讲述了Yii CGridView用法。分享给大家供大家参考,具体如下:CGridView的功能是用来显示的数据列表。它支持排序,分页,和AJAX数据请求。CGridView最好使用 data provider,最好是 CActiveDataProvider 。简单代码如下:$dataProvider=new CActiveDataProvider(&
本文实例讲述了Yii CGridView用法。分享给大家供大家参考,具体如下:
CGridView的功能是用来显示的数据列表。它支持排序,分页,和AJAX数据请求。
CGridView最好使用 data provider,最好是 CActiveDataProvider 。
简单代码如下:
$dataProvider=new CActiveDataProvider('Post');
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
));详细示例:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
'title', // display the 'title' attribute
'category.name', // display the 'name' attribute of the 'category' relation
'content:html', // display the 'content' attribute as purified HTML
array( // display 'create_time' using an expression
'name'=>'create_time',
'value'=>'date("M j, Y", $data->create_time)',
),
array( // display 'author.username' using an expression
'name'=>'authorName',
'value'=>'$data->author->username',
),
array( // display a column with "view", "UPDATE" and "DELETE" buttons
'class'=>'CButtonColumn',
),
),
));更多关于Yii CGridView用法实例详解请关注PHP中文网(www.php.cn)其它文章!