I have a CGridView on my view and it works fine. How ever, I need to bind a model variable so that my Advance Search function will be included. My current setup gives an error of Undefined variable: arrayDataProvider.
index.php (View)
$this->renderPartial('search',array(
'model'=>$model,
));
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $arrayDataProvider,
'columns' => array(
array(
'name' => 'LastName',
'type' => 'raw',
'value' => 'CHtml::encode($data["LastName"])',
),
array(
'name' => 'FirstName',
'type' => 'raw',
'value' => 'CHtml::encode($data["FirstName"])',
),
array(
'name' => 'Email',
'type' => 'raw',
'value' => 'CHtml::encode($data["Email"])',
),
),
));
Controller
public function actionIndex()
{
$model=new TblAccountdetails('search');
$model->unsetAttributes(); // clear any default values
$data = new TblAccountdetails();
$rawData = $data->getAllData();
$arrayDataProvider=new CArrayDataProvider($rawData, array(
'keyField'=>'AID',
'pagination'=>array(
'pageSize'=>10,
),
));
$params =array(
'arrayDataProvider'=>$arrayDataProvider,
);
$this->render('index',array(
'model' =>$model,
'dataProvider' =>$params,
));
}
You put your $arrayDataProvider
in array $params
and then pass it in view like $dataProvider
variable:
$params =array(
'arrayDataProvider'=>$arrayDataProvider,
);
...
$this->render('index',array(
'model' =>$model,
'dataProvider' =>$params,
));
Then in View you should get this variable from array $dataProvider
:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider['arrayDataProvider'],
...
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments