douqiu1604
douqiu1604
2012-12-18 04:18
浏览 39
已采纳

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

I've not found here how we can get builded query by Phalcon\Mvc\Model\Criteria in docs: http://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Criteria.html

Is it possible?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douliao5467
    douliao5467 2012-12-18 05:52
    已采纳

    Phalcon\Mvc\Model\Criteria builds an array of valid parameters for SomeModel::find, or SomeModel::findFirst, this class does not build a real query.

    Furthermore, we have Phalcon\Mvc\Query\Builder this class has the ability to build PHQL queries:

    <?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();
    

    More info: http://docs.phalconphp.com/en/latest/reference/phql.html#creating-queries-using-the-query-builder

    点赞 评论

相关推荐