0

这是我的代码,我怎么可以给 orderby 。

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

在这里我想给order by TravancoMarketing.id DESC

我怎么给这个?

4

2 回答 2

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'));
于 2012-09-18T09:48:27.547 回答
0

在您的控制器中,您应该声明如下内容:

public $paginate = array(
        'order' => array(
            'TravancoMarketing.id' => 'DESC'
        )
    );
于 2012-09-18T09:48:39.723 回答