Manual filtering on CActiveDataProvider

Dear all,

When using CActiveDataProvider, sometime I can’t just use CDbCriteria and have to filter the result

afterwards. for example:




public function search() {

   # stuff for creating CDbCriteria

   $activeDataProvider = new CActiveDataProvider($this, array(

      'criteria' => $criteria,

      'pagination' => array(

         'pageSize' => 10,

      ),

   ));

   

   # manual filtering on the $activeDataProvider->data

   $data = $activeDataProvider->data;

   $count = count($data);

   for ($i = 0; $i < $count; $i++) {

      if ($data[$i]->complicatedLogic()) {

         unset($data[$i]);

      }

   }

   # unset() don't re-index, so use array_values() here

   $activeDataProvider->setData(array_values($data));

   

   return $activeDataProvider;

}



However, each time the ‘manually filtering’ part only get one ‘page’ of data but not the whole set.

What I want is paginate the data after manual filtering. Even I set the pagination in the following way

doesn’t work:




$activeDataProvider = new CActiveDataProvider($this, array(

   # ...

   'pagination' => false,

));


# manual filtering

# ...


# set the pagination

$pages = new CPagination(count($activeDataProvider->data));

$pages->pageSize = 10;

$activeDataProvider->setPagination($pages);




Thanks in advance.

Use CArrayDataProvider.

Happy Coding.