在数据查询的时候,出现下面的是什么意思?
$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条记录

相关文章:

  • 2022-12-23
  • 2021-07-15
  • 2021-05-23
  • 2021-11-28
  • 2021-11-19
猜你喜欢
  • 2021-12-15
  • 2021-10-03
  • 2022-12-23
  • 2021-06-02
  • 2021-10-19
  • 2022-12-23
  • 2021-07-26
相关资源
相似解决方案