displaying Cgridview in yii

这一生的挚爱 提交于 2019-12-11 14:39:21

问题


how can i display a record in Cgridview?

tbl_book:
id
title
author


tbl_in_out:
id
book_id
date_out
date_in

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!


回答1:


Basic grid view:

// 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));


来源:https://stackoverflow.com/questions/9555410/displaying-cgridview-in-yii

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!