views:

6

answers:

1

Hi all,

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:

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'))));
+2  A: 

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.

Mike
Yes you're right, Mike.Thanks