Luciano Nascimento
Luciano Nascimento

Reputation: 2600

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

Upvotes: 1

Views: 2418

Answers (1)

wonde
wonde

Reputation: 1181

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;
}

Upvotes: 10

Related Questions