【问题标题】:How to use "Models::find()" in phalcon framework?如何在 phalcon 框架中使用“Models::find()”?
【发布时间】:2013-05-14 06:44:57
【问题描述】:
$submodules = Modules::find(
    array(
        'moduleid in (:mods:) and parentid = :parentid:',
        'bind' => array(
            'mods' => '1,2',
            'parentid' => 1
        ),
        'bindtype' => array(
            'mods' => Column::BIND_PARAM_STR,
            'parentid' => Column::BIND_PARAM_INT
        )
    )
);

我希望 sql 是“从模块中选择 * (1,2) 和 parentid = 1 的模块” 但结果不正确。

请帮忙。

【问题讨论】:

    标签: models phalcon


    【解决方案1】:

    转义 :mods: 将产生 '1,2' 因此:select * from modules where moduleid in ('1,2') and parentid = 1

    您需要为“in”中的每个值使用绑定参数:

    $submodules = Modules::find(array(
      'moduleid in (:firstMod:, :secondMod:) and parentid = :parentId:',
      'bind' => array(    
        'firstMod' => 1,
        'secondMod' => 2,
        'parentId' => 1
      )
    ));
    

    这种情况下最好使用QueryBuilder

    【讨论】:

    • $modules = $this->modelsManager->createBuilder() ->from('Modules') ->inWhere('moduleid',[1,2]) ->orderBy('sortid ASC ') ->getQuery() ->execute();我使用了 QueryBuilder 但输出 502 错误!
    • inWhere('Modules.moduleid')
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    • 2019-07-28
    • 2013-04-03
    • 2012-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多