如何在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中(对不起英语不好)。请帮忙!
答案 0 :(得分:3)
基本网格视图:
// 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'
)
));
您需要从控制器传递数据提供者:
$dataProvider=new CActiveDataProvider('InOut'); // assuming the name of your model for tbl_in_out is InOut
$this->render('gridviewname',array('dataProvider'=>$dataProvider));