Hello all,
i have been developing a couple of projects using Yii Framework and now i have some problems on the CActiveDataProvider object.
i am talking about the search() function on the model file (this function is being used from the admin view).
Here is what i do:
$data = new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
Instead of the usual
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
-
Getting data from CBbCriteria ($data->getData()).
-
Filter each record ( accordingly to the permission a user has on the record, show it or don’t show it ).
$output=array();
foreach($data->getData() as $record)
{
if( My system checks if current user logged has access to view this $record->id)
$output[]=$record;
}
- Once i have the $output data i want, i do a $data->setData($output); and $data->setTotalItemCount(count($output)); so basically the top-gridview shows the number of results filtered (not the total number of results).
The problem comes with pagination.
-
Initial $data from CActiveDataProvider object, returns the only the first 10 results (default number of results per page).
-
What happens if on the first 10 results, there are no $records to show but it has $records on the second page?
Basically it shows no results on the gridView first page, but the paginator shows page 1 and 2. (the first page shows no results, and the second shows records).
How could fix this?
i mean, i would like the paginator to work accordingly the $output array, instead of $data initial array, so if there are no results on the first page just show a first page with the records from the second.
Hope to get it explained correctly!
Thanks.