PhalconPHP结合params和oerder

时间:2015-04-01 08:27:24

标签: sql-order-by phalcon

以下是我尝试过的代码

$conditions = "category = :id: AND status = :status: ORDER BY :order: LIMIT 3";

$parameters = array(
    "id" => $cat_id,
    "status" => 1,
    "order" => "title ASC",
);

$posts = Posts::find(array(
    $conditions,
    "bind" => $parameters
));

一切都很好,除了顺序。你能帮我找一下在PhalconPHP中使用订单的正确方法吗?

1 个答案:

答案 0 :(得分:1)

“bind”和“order”是separate parameters

$conditions = "category = :id: AND status = :status:";

$parameters = array(
    "id" => $cat_id,
    "status" => 1,
);

$posts = Posts::find(array(
    "conditions" => $conditions,
    "bind" => $parameters,
    "order" => "title ASC",
    "limit" => 3
));

这是一种干净可靠的方法 - 这样您就可以在条件非常严格的条件下。您可以根据请求参数更改限制/订单,而无需触及条件字符串。