Clistview in yii Undefined variable dataProvider

I need a list in my index.php . This model has no model, so I used CSqlDataProvider to declare a data provider and expose 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 the error

"Undefined variable: dataProvider"

0


source to share


1 answer


Yours itemView

cannot be index

. It should be a partial view that will display the items in your list. $dataProvider

is available when the list is displayed, but not when the items are rendered, hence the error. For more information http://www.yiiframework.com/doc/api/1.1/CListView#itemView-detail



+2


source







All Articles