在 yii 中显示 Cgridview [英] displaying Cgridview in yii

查看:54
本文介绍了在 yii 中显示 Cgridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Cgridview 中显示记录?

how can i display a record in Cgridview?

tbl_book:
id
title
author


tbl_in_out:
id
book_id
date_out
date_in

我创建了一个关系,tbl_in_out 中的 book_id 属于 tbl_book 中的 id.我想要做的是使用tbl_book中的相应数据查询tbl_in_out中的记录并将其显示在CGridview中(对不起,英语不好).请帮忙!

I have created a relationship that the book_id in tbl_in_out belongs to id in tbl_book. what i want to do is to query a record in the tbl_in_out with the corresponding data in tbl_book and display it in the CGridview(sorry for the bad english). Please help!

推荐答案

基本网格视图:

// the following code goes in your view
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
    'book.title', // assuming the name of the relation is "book" in model of tbl_in_out
    'book.author',
    'date_out',
    'date_in'
)
));

您需要从控制器传递数据提供者:

You'll need to pass the data provider from the controller:

$dataProvider=new CActiveDataProvider('InOut'); // assuming the name of your model for tbl_in_out is InOut
$this->render('gridviewname',array('dataProvider'=>$dataProvider));

这篇关于在 yii 中显示 Cgridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆