That’s not quite right as the criteria is a property of the CActiveDataProvider, not the model. Try setting the scopes in the CActiveDataProvider returned by the model’s search method.
I would rather recommend you to add some value to the model attribute that works the same as the scope you want to apply, if you can.
public function actionIndex()
{
$model=new Deliverable('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Deliverable']))
$model->attributes=$_GET['Deliverable'];
$model->xxx = $someValue; // a value that works the same as the scope
$this->render('index',array(
'model'=>$model,
));
}
By doing this, your CGridView (or CListView) will show only the deliverables whose xxx is $someValue.
$model in this method is a container of search parameters. And the values of the attributes works as the filtering conditions.
That would be the better option for simpler filters, however I have some really complicated scopes in my current project that would be a pain to rewrite into the controller, so I thought I’d recommend adding the scope to the search() method as that’d be a favourable option in the case of complicated scopes like some I’m working on at the moment.
No, I don’t think so. I agree that the scopes are very handy.
I thought that filthy may want to understand CActiveDataProvider and Model::search() method clear enough to blow off the fog. So I wanted to show a simple way.