服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - PHP教程 - Yii CGridView用法实例详解

Yii CGridView用法实例详解

2021-02-04 16:08Flowf PHP教程

这篇文章主要介绍了Yii CGridView用法,结合实例形式分析了CGridView的功能、用法与相关属性用法,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了Yii CGridView用法。分享给大家供大家参考,具体如下:

CGridView的功能是用来显示的数据列表。它支持排序,分页,和AJAX数据请求。

CGridView最好使用 data provider,最好是 CActiveDataProvider

简单代码如下:

?
1
2
3
4
$dataProvider=new CActiveDataProvider('Post');
$this->widget('zii.widgets.grid.CGridView', array(
  'dataProvider'=>$dataProvider,
));

详细示例:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$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',
    ),
  ),
));

属性说明:

actionPrefix 方法前辍

afterAjaxUpdate AJAX成功响应后调用的JAVASCRIPT函数

ajaxUpdate 是否启用AJAX请求数据

ajaxUpdateError AJAX失败响应后调用的JAVASCRIPT函数

ajaxUrl AJAX请求的URL

ajaxVar AJAX请求,使用GET方式传送的变量

baseScriptUrl 视图资源的URL

beforeAjaxUpdate 在AJAX调用之前调用的JAVASCRIPT函数

blankDisplay 列标题为空显示的内容

columns 内容列有配置

controller 控制器

cssFile 视图的样式

dataProvider 视图的数据

emptyText 内容为空显示的信息

filterPosition 搜索框所在的位置

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

延伸 · 阅读

精彩推荐