我怎样才能在cakephp中设置orderby

时间:2012-09-18 09:35:19

标签: cakephp sql-order-by

这是我的代码,在这里我该如何给出orderby。

$this->set('added', $this->paginate('TravancoMarketing', array('status = 0', 'assigned_by = '.$user_level)));

我想在此提供order by TravancoMarketing.id DESC

我怎么能给这个?

2 个答案:

答案 0 :(得分:1)

您可以将其作为默认订单添加到TravancoMarketing模型中:

class TravancoMarketing {

    public $order = array('TravancoMarketing.id'=>'DESC');

}

或分页查询本身:

$this->paginate = array(
    'conditions'=>array(
        'TravancoMarketing.status'=>0,
        'TravancoMarketing.assigned_by'=>$user_level
    ),
    'order'=>array(
        'TravancoMarketing.id'=>'DESC'
    )
);

$this->set('added', $this->paginate('TravancoMarketing'));

答案 1 :(得分:0)

在你的控制器中你应该声明这样的东西:

public $paginate = array(
        'order' => array(
            'TravancoMarketing.id' => 'DESC'
        )
    );