Using resetScope in CActiveDataProvider

Hi All,

I was going through the Yii app reference for overriding the default Scope and found out about resetScope. for a simple table read, we can use it as MyModel::model()->resetScope->findAll();

But the problem is how to use it if I have a scenario defined in the model, e.g. the search() function which is automatically created by the Yii crud where the result is generated using CActiveDataProvider in the model.

The query statement in the search function is something like:


return new CActiveDataProvider('MyModel', array(

			'criteria'=>$criteria,

		));

In this case, how can we use the resetScope method as we are directly querying the table without creating an instance.

No replies yet!!!

Well, I thought giving the following a try without success:


in controller:

$model=new MyModel('search');


in view:

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

...

'dataProvider'=>$model->resetScope()->search(),

...



When I use MyModel::model()->resetScope()->findAll(), the reset works perfectly.

Any help?

In the controller’s action:




// ...

$criteria = new CDbCriteria();

// ...

$dataProvider = new CActiveDataProvider(

    MyModel::model()->resetScope(),  // It's a model finder, and NOT a result set

    array(

        'criteria'=>$criteria,

        // ...

    ),

);

// ...

$this->render('myView', array('dataProvider'=>$dataProvider));



In the view:




// ...

$this->widget(

    'zii.widgets.grid.CGridView',

    array(

        // ...

        'dataProvider'=>$dataProvider,

        // ...

    )

);

// ...