When to use CActiveDataProvider?

Hey community,

I have 2 questions concerning the CActiveDataProvider:

  1. When to use CActiveDataProvider and when a model? Both (e.g. admin and index actions) just deliver the db content based on ActiveRecords (like documentation explains).

  2. I tried to apply criteria to both gii-generated actions attached below. It works, but did I do it the way it’s meant to be done?

The gii-generated index works with CActiveDataProvider

index action:

public function actionIndex()


        $criteria=new CDbCriteria;

        $criteria->addCondition('topic LIKE "%castle%"');

		$dataProvider=new CActiveDataProvider('Grade', array(







index view:

$this->widget('zii.widgets.CListView', array(




whereas the admin action uses a model

admin action:

	public function actionAdmin()


		$model=new Grade('search');

		$model->unsetAttributes();  // clear any default values









admin view:

$this->widget('zii.widgets.grid.CGridView', array(




Thank you very much for your support.


CActiveDataProvider is actually a "level above" a model. Its mainly used with list views like CGridView. It contains (or better: provides) a list of models (data) that represent a single page in a larger resultset. It also contains the respective pagination and sort objects.

Mike, thank you for your explanation.