html5里面的find(‘first’)怎么应用?

来源:互联网 发布:python 抓取网络数据 编辑:程序博客网 时间:2024/05/19 15:22
find(‘first’)

find('first', $params)将返回一个结果,你会使用这个在任何情况下,你希望只有一个结果。下面是几个简单的例子(controller code):
public function some_function() {    // ...    $semiRandomArticle = $this->Article->find('first');    $lastCreated = $this->Article->find('first', array(        'order' => array('Article.created' => 'desc')    ));    $specificallyThisOne = $this->Article->find('first', array(        'conditions' => array('Article.id' => 1)    ));    // ...}



在第一个示例中,没有参数传递给找到,因此没有条件或将使用排序顺序。从找到返回的格式find('first')调用的形式:

Array(    [ModelName] => Array        (            [id] => 83            [field1] => value1            [field2] => value2            [field3] => value3        )    [AssociatedModelName] => Array        (            [id] => 1            [field1] => value1            [field2] => value2            [field3] => value3        ))


0 0