CakePHP:无法根据多个条件进行订购


CakePHP: unable to order by multiple criteria

我在CakePHP上,我已经阅读了关于检索数据的文档,它清楚地表明多个ORDER BY是可能的。然而,我无法让它发挥作用。它只适用于一个,但当我将其更改为具有两个字符串的数组时,似乎两者都不适用。我做错了什么?

private function _bundle_users( $report ) {
    $this->loadModel("User");
    $conditions = array(
        'ReportsUser.report_id' => $report['Report']['id']
    );
    //$order = 'ReportsUser.created DESC'; //THIS WORKS FINE
    $order = array( //THIS SEEMS TO RESULT IN BOTH GETTING IGNORED
            'ReportsUser.created DESC', 
            'User.last_name ASC',
            );
    $this->User->bindModel(array('hasOne' => array('ReportsUser')), false);
    $this->paginate = array('conditions'=>$conditions, 'contain'=>array('ReportsUser', 'Attempt'=>array('order' => 'Attempt.created DESC'), 'Tag', 'Resume', 'School'),
        'order'=>$order
        );
    $users = $this->Paginate('User');
    return $users;
}

我想我做的和这个例子完全一样,除了bindModel()。也许这是一条相关的线索。

更新1

按预期工作:$order = 'ReportsUser.created DESC';

但这被忽略了:$order = array('ReportsUser.created DESC');

数组语法似乎是问题的一部分。

更新2

当我使用key=>值格式时,数组语法也被忽略:'ReportsUser.created' => 'DESC'

更新3感谢@Leonard,有效,尽管医生说:

$order = 'ReportsUser.created DESC, User.last_name ASC';

我对CakePHP不是很熟练,但通过阅读文档,我会尝试一下:

$order = array(
    'ReportsUser.created' => 'desc',
    'User.last_name' => 'asc',
);

根据文档,这不是的方法,但你尝试过吗:

$order = 'ReportsUser.created DESC, User.last_name ASC';