开发者

Fail to sort data in DESC data in FindAllBySomething

开发者 https://www.devze.com 2023-01-06 09:40 出处:网络
I am using cakePHP 1.26. I am trying to sort the data by Date in DESC order but of no luck. $this->set(\'posts\', $this->Post->findAllByZero(\'0\', array(\'order\'=>array(\'Post.createda

I am using cakePHP 1.26. I am trying to sort the data by Date in DESC order but of no luck.

 $this->set('posts', $this->Post->findAllByZero('0', array('order'=>array('Post.createdate DESC'))));

I can't figure out what's wrong in the code as shown above. Could you help me please?

Edited reason:开发者_Python百科

I have altered the code and it is able to sort the data by date in DESC order,

but I am not sure if there is the best way do it:

 $this->set('posts', $this->Site1->find('all', array('conditions'=>array('Post.zero'=>'0'), 'order'=>array('Post.created DESC'))));


You can't specify the order, or any other option for that matter, in findBy<fieldname>() and findAllBy<fieldname>() methods because they accept only one argument, the value you're looking for. I'm afraid you'll have to use the find() method instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号