Clistview in yii Undefined variable dataProvider

青春壹個敷衍的年華 提交于 2019-12-20 06:22:44

问题


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

Here is my index.php code....

$this->widget('zii.widgets.CListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'index',
    'id'=>'list',
    ));

I am getting an error

"Undefined variable: dataProvider"


回答1:


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



来源:https://stackoverflow.com/questions/14979058/clistview-in-yii-undefined-variable-dataprovider

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