我有以下代码:
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
中给出了回复。
我做错了什么?
答案 0 :(得分:3)
conditions
和order
键位于同一个数组中,正确的语法是
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);