h1

A simple way to order results in a pagination query

May 29, 2007

In the controller, put this piece of code:


$this->paginate = array('order' => 'Topic.created DESC');
$this->set('topics', $this->paginate(array('Topic.board_id' => $id)));

5 comments

  1. Somehow i missed the point. Probably lost in translation :) Anyway … nice blog to visit.

    cheers, Shankar.


  2. Hmm, it looks confusing to me now too :)

    I think I was trying to order the results on Topic.created DESC and once that was set, you pass the topics variable as you would normally.


  3. Thanks!!! I’ve been looking for a way to change the display order based on different paginated models in the same controller. i was starting to think cakePHP’s native pagination support couldn’t do this… simply and eloquent.


  4. thanks for this, after 2 hours of headache.


  5. many thanks!!! :)



Leave a Comment