温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CGridView怎么在Yii 框架中使用

发布时间:2021-01-15 16:46:35 来源:亿速云 阅读:149 作者:Leah 栏目:开发技术

CGridView怎么在Yii 框架中使用?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

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',
    ),
  ),
));

属性说明:

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 搜索框所在的位置

关于CGridView怎么在Yii 框架中使用问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI