CakePHP paginate and order by

后端 未结 4 749
南方客
南方客 2021-01-15 03:10

It feels like I\'ve tried everything so I now come to you.

I am trying to order my data but it isn\'t going so well, kinda new to Cake.

This is my code:

4条回答
  •  无人及你
    2021-01-15 03:52

    Try

    $this->set('threads', $this->paginate('Thread', array(
            'Thread.hidden' => 0,
            'Thread.forum_category_id' => $id
        ),
        array(
            'Thread.created' => 'desc'
        )
    ));
    

    I'm not a Cake master, just a guess.

    EDIT. Yes, thats right. Cake manual excerpt:

    Control which fields used for ordering ... $this->paginate('Post', array(), array('title', 'slug'));

    So order is the third argument.

提交回复
热议问题