Luciano Nascimento Luciano Nascimento - 6 months ago 19
PHP Question

Get CActiveDataProvider data in the View

How to get

CActiveDataProvider
data directly, without using
CGridView
?

Controller.php

public function actionList($id)
{
$criteria = new CDbCriteria;

$dataProvider=new CActiveDataProvider('Events', array(
'criteria' => $criteria
));

$this->render('list',array(
'dataProvider'=>$dataProvider,
));
}


View.php:

<?php echo $dataProvider->name; ?> // Return Error

Answer

CActiveDataProvider provides data in terms of ActiveRecord objects , use getData() method to get all activerecord objects that are in the dataprovider

$models =$dataProvider->getData()

foreach($models as $model)
{
 echo $model->name;
}