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"
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