有没有办法通过Phalcon \ Mvc \ Model \ Criteria进行汇编查询?

时间:2012-12-18 04:18:27

标签: php model criteria phalcon

我在这里找不到如何通过文档中的Phalcon \ Mvc \ Model \ Criteria获取构建查询: http://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Criteria.html

有可能吗?

1 个答案:

答案 0 :(得分:4)

Phalcon \ Mvc \ Model \ Criteria为SomeModel :: find或SomeModel :: findFirst构建一个有效参数数组,此类不构建实际查询。

此外,我们有Phalcon \ Mvc \ Query \ Builder这个类有能力构建PHQL查询:

<?php

//Get the PHQL to be generated
$phql = $this->modelsManager->createBuilder()
    ->from('Robots')
    ->limit(20);
    ->order('Robots.name')
    ->getPhql();

//Execute the query
$robots = $this->modelsManager->createBuilder()
    ->from('Robots')
    ->limit(20);
    ->order('Robots.name')
    ->getQuery()
    ->execute();

更多信息:http://docs.phalconphp.com/en/latest/reference/phql.html#creating-queries-using-the-query-builder