[Yii Framework] 数据库查询

在数据查询的时候,出现下面的是什么意思?
$posts=Post::model()->published()->recently()->findAll();

这个是叫做named scope,
每个命名范围被声明为一个可以被用来初始化CDbCriteria阵列实例。
如要下面的例子
class Post extends CActiveRecord
{
......
public function scopes()
{
return array(
’published’=>array(
’condition’=>’status=1’,
),
’recently’=>array(
’order’=>’createTime DESC’,
’limit’=>5,
),
);
}
}
而$posts=Post::model()->published()->recently()->findAll();的意思就是找出最新的status为1的post的5条记录

原文地址:https://www.cnblogs.com/davidhhuan/p/1717045.html