问题描述
我需要一个列表视图在我的的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 code ....
Here is my index.php code....
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'index',
'id'=>'list',
));
我得到一个错误
未定义的变量:dataProvider中
需要帮助,请尽快解决这个问题。我是新来的的Yii
Need help urgently please solve this issue . I am new to Yii.
推荐答案
您 ItemView控件
不能首页
。它必须将呈现在你的列表中的项目的局部视图。正在呈现当列表而不是当项目被渲染,因此误差 $ dataProvider中
可用。欲了解更多信息
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
这篇关于CListView中在Yii中未定义的变量的dataProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!