default condition in a model

I have field in my Employees table called ‘IsActive’. I want to use it to list only the Active Employees in EVERY listing of Employees. Something like:



In your model’s search function add:


That works at least for actions that use $model = new Employees(‘search’), like the default admin page which uses that for its CGridView.

Thanks. I tried that but when I comment out that line in the actionIndex function that I have a new CDbCriteria created, it didn’t work in that page. :-[

Read the section about "Default Named Scope" here:

Thank You :D Setting up the defaultScope did the trick.

Sometimes the docs really help ;D but for us newbies, there’s soooooo much that one doesn’t really know what to look for (filter, scope, etc) in order to be able to look for it…Oh well, Thanks again.

That’s what the forum is for… ;)