문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top