We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

PhalconPHP bind params and oerder by

Here is the code what I've tried

$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 ));

Everything is fine except order by. Can you please help me to find out the proper way to use order by in PhalconPHP?



3.5k
Accepted
answer
edited Apr '15

you must define mandatory key order and limit,

$conditions = "category = :id: AND status = :status: ";
$parameters = array( "id" => $cat_id, "status" => 1 );
$posts = Posts::find(array( 
    $conditions, 
    "bind" => $parameters, 
    "order" => "order DESC", 
    "limit" => "30" 
));

In addition look here: https://docs.phalcon.io/es/latest/reference/models.html