开发者

Fail to sort data in DESC data in FindAllBySomething

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜