I’ll preface this with, I’m new to Yii as of last week and I’m loving it! Can’t wait to really get it figured out (what’s available, where to put code, etc).
Now to the point. Is it possible to make a base class with scopes and extend that class with other scopes in the new class. Such that the scopes from both the new class and the parent class available?
Class Article extends CActiveRecord
{
...
public function scopes()
{
return array(
'published'=>array(
'condition'=>'status=published',
),
);
}
...
}
Class Commentary extends Article
{
...
public function scopes()
{
return array(
'recent'=>array(
'condition'=>'createdate >' . $daysAgo,
'order'=>'createdate DESC',
),
);
}
...
}
// Then feed this to an ActiveDataProvider in the controller:
$criteria = new CDbCriteria(array(
'scopes'=>array('published','recent'),
));
The idea is to pack all article commonalities into the base class and then have specific classes for things like News, Commentary, Post, Blog, etc…
Please let me know if this is possible and/or if I’m even on the right track.
Thanks