I’ve a custom data provider in my Model
I tryied this in controller
public function actionMonthTotal()
{
$model=new Rapporti();
$this->render('monthTotal',array(
'dataProvider'=>$model->monthTotal(),
));
}
Where monthTotal is the model function that give me a DataProvider
Actually ‘monthTotal’ is a copy/past of view.php and it uses a clistView using _monthTotal, that is a copy/past of _view.php
I Need to simply get the dataset from dataProvider (a ‘SELECT COUNT, SUM, SUM, etc…”) and iterate into recordset to echo a simple TABLE into monthTotal view . So …
how to use a dataProvider from a view to get records and how to iterate trough recors?
My month total is this and is in ‘Report’ Model
Actually report is in a relation Report N -> 1 Pionierato (sorry for italian terms, but are only object names)
public function totalMonth() {
$criteria = new CDbCriteria();
$criteria->with = array ('pionierato');
$criteria->condition = 'dataBetel=:month';
$criteria->select = "COUNT(t.id) as numProclamatori,
pionierato.tipo as tipoPionierato,
SUM(libri) as sommaLibri,
SUM(opuscoli) as sommaOpuscoli,
SUM(ore) as sommaOre,
SUM(riviste) as sommaRiviste,
SUM(visite) as sommaVisite,
SUM(studi) as sommaStudi";
$criteria->group = "t.dataBetel, t.pionieratoId";
$criteria->params = array ('month' => "2012-09-01");
$dataProvider=new CActiveDataProvider('Rapporti',
array ('criteria' => $criteria)
);
return $dataProvider;
}
I need to use this dataprovider to get the 3 record it will output and print a 3-row table. Static.
Using suggestion from first answer, i got this:

Try:
That should work, you are creating an object with the name $model which has a value equal to the return value of the method monthTotal() in the Rapporti model
If that doesn’t work, check that you are actually getting a result from your monthTotal function by copying it (minus the return part) into your controller instead of calling it from the model.
In your monthTotal view you can iterate through the active records using CListView like so:
Each iteration calls in a subview called “_view”. The data for that record can be accessed using $data (eg: $data->id);
Here is an example of querying without using CActiveDataprovider:
You can try that… Alternatively you can use findAllBySql() instead of findAll() and type in your query that way. You will then be able to iterate through your data set using a foreach() loop