DESC的CakePHP订单无效

时间:2016-08-01 11:09:48

标签: cakephp

我有以下代码:

if($item_id!=0)
{
  $conditions = array(
    'AND' => array(
      array('OR' => array(array('Message.receiver_id' =>$member_id), 
      array('Message.member_id' =>$member_id))), array('Message.item_id'=>$item_id)));
}
else if($trip_id!=0)
{
  $conditions = array(
    'AND' => array(
      array('OR' => array(array('Message.receiver_id' =>$member_id), 
      array('Message.member_id' =>$member_id))), array('Message.trip_id'=>$trip_id)));
}
$lastMessage=$this->Message->find('all',array('conditions'=>$conditions),
array('order'=>'Message.id DESC'));
print_r($lastMessage);

代码返回所需的结果。 唯一的问题是 NOT DESCENDING ORDER of id中给出了回复。

我做错了什么?

3 个答案:

答案 0 :(得分:3)

conditionsorder键位于同一个数组中,正确的语法是

find(
    'all',
    array(
        'conditions'=>$conditions,
        'order'=> 'Message.id DESC'
    )
);

'order' => array('Message.id' => 'desc')

答案 1 :(得分:1)

试试这个:

$lastMessage=$this->Message->find('all', array('conditions' => $conditions,'order'=>array('Message.id' => 'DESC')));

答案 2 :(得分:-2)

if($item_id!=0)
{
    $conditions = array(
        'AND' => array(
            array('OR' => array(array('Message.receiver_id' =>$member_id),
            array('Message.member_id' =>$member_id))
            ),
            array('Message.item_id'=>$item_id)   
        )
    );
}
else if($trip_id!=0)
{
    $conditions = array(
        'AND' => array(
            array('OR' => array(array('Message.receiver_id' =>$member_id),
            array('Message.member_id' =>$member_id))
            ),
            array('Message.trip_id'=>$trip_id)   
        )
    );
}

$conditions = array('order' => 'Message.id DESC');

$lastMessage=$this->Message->find('all', array('conditions' => $conditions));
print_r($lastMessage);