yii 中的 Clistview 未定义变量 dataProvider [英] Clistview in yii Undefined variable dataProvider
问题描述
我的 index.php 中需要一个列表视图.这没有任何模型,所以我使用 CSqlDataProvider 来声明数据提供者并将其从控制器呈现到索引.这是我的控制器操作...
I need a list view in my index.php. This is does not have any model so I used CSqlDataProvider for declaring the data provider and rendering it to the index from the controller. Here is my controller action...
public function actionIndex()
{
$sql="select * from Ads";
$totalItemCount=20;
$dataProvider = new CSqlDataProvider($sql, array(
'totalItemCount' => $totalItemCount,
));
$this->render('index',array('dataProvider'=>$dataProvider));
}
这是我的 index.php 代码....
Here is my index.php code....
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'index',
'id'=>'list',
));
我收到一个错误
未定义变量:dataProvider"
"Undefined variable: dataProvider"
推荐答案
你的 itemView
不能是 index
.它必须是将呈现列表中的项目的局部视图.$dataProvider
在呈现列表时可用,但在呈现项目时不可用,因此出现错误.更多信息 http://www.yiiframework.com/doc/api/1.1/CListView#itemView-detail
Your itemView
cannot be index
. It has to be a partial view that will render the items in your list. $dataProvider
is available when the list is being rendered but not when the items are being rendered hence the error. For more information http://www.yiiframework.com/doc/api/1.1/CListView#itemView-detail
这篇关于yii 中的 Clistview 未定义变量 dataProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!