cakephp条件或订单排序不起作用

时间:2015-12-31 18:46:11

标签: php cakephp cakephp-2.0

代码不工作条件正常但订单排序无效

请帮我解决问题

$this->Offer->find(
    'all',
    array(
        'conditions' => array(
            'OR' => array(
                array('Offer.branch_id' => 1),
                array('Offer.branch_id' => $branch['Branch']['id'])
            )
        )
    ),
    array('order' => array('Offer.order_no' => 'DESC'))
);

2 个答案:

答案 0 :(得分:1)

试试此代码: - >

$this->Offer->find(
    'all',
    array(
        'conditions' => array(
            'OR' => array(
                array('Offer.branch_id' => 1),
                array('Offer.branch_id' => $branch['Branch']['id'])
            )
        ),
        'order' => array('Offer.order_no' => 'DESC')
    )
);

答案 1 :(得分:0)

$this->Offer->find('all', array(
    'conditions' => array(
        'OR' => array(
            'Offer.branch_id' => 1,
            'Offer.branch_id' => $branch['Branch']['id']
        )
    ),
    'order' => array('Offer.order_no DESC')
));
  1. 在OR =>数组,再没有数组,
  2. 在条件之后下订单,并使格式如'order'=>数组('Offer.order_no DESC') ,
  3. DESC =降序,是从最后排序order_no ASC =升序,从第一个开始排序