我想使用表 created
中的字段 Users
在 cakephp 中检索最后 3 个注册用户。
在我的 Controller 中,我有:
$this->User->recursive = 1;
$this->set('users',
$this->User->find('all',
array('conditions'=> array(
'limit' => 3,
'order' => array(
'created' => 'asc'
)
)
)
)
);
运行时上面的代码返回此错误:
Syntax error or access violation: 1064 You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 'order = ('asc')' at line
我必须怎么做才能解决错误?
最佳答案
尝试这样的事情:
$this->set('users', $this->User->find('all', array(
'limit' => 3,
'order' => 'User.created DESC',
'recursive' => 1,
)));