2012-03-04 60 views
0

如何在Cgridview中顯示記錄?在yii中顯示Cgridview

tbl_book: 
id 
title 
author 


tbl_in_out: 
id 
book_id 
date_out 
date_in 

我已經創建了一個在tbl_in_out的book_id屬於ID在tbl_book的關係。 我想要做的就是在tbl_in_out中查詢tbl_book中的相應數據並將其顯示在CGridview中(對不起英語不好)。請幫忙!

+0

我婉顯示在cgridview將是colums什麼|標題|作者|約會|日期在... ... – 2012-03-04 13:51:25

回答

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)); 
+1

謝謝你,這工作很好! – 2012-03-04 16:30:50

+0

歡迎您在cgridview類中有更多的東西,您應該在文檔中查看它。 – 2012-03-04 16:34:06