html5的find(‘count’)、find(‘all’)的案例

来源:互联网 发布:搜了网络股票代码 编辑:程序博客网 时间:2024/05/19 12:14
find(‘count’)


find('count',$params)返回一个整数值。下面是几个简单的例子(controllercode):

public function some_function() {    // ...    $total = $this->Article->find('count');    $pending = $this->Article->find('count', array(        'conditions' => array('Article.status' => 'pending')    ));    $authors = $this->Article->User->find('count');    $publishedAuthors = $this->Article->find('count', array(       'fields' => 'DISTINCT Article.user_id',       'conditions' => array('Article.status !=' => 'pending')    ));    // ...}


不要通过字段作为一个数组find('count')。您只需要指定字段不同计数(因为否则,伯爵始终是相同的——由条件)。


find(‘all’)

find('all', $params)返回一个数组(可能有多个)的结果。它实际上是使用的机制都发现()变异,以及随意翻阅。下面是几个简单的例子(controller code):

public function some_function() {    // ...    $allArticles = $this->Article->find('all');    $pending = $this->Article->find('all', array(        'conditions' => array('Article.status' => 'pending')    ));    $allAuthors = $this->Article->User->find('all');    $allPublishedAuthors = $this->Article->User->find('all', array(        'conditions' => array('Article.status !=' => 'pending')    ));    // ...}


0 0
原创粉丝点击