Search code examples
angularjscakephppaginator

CakePHP Pagination Order by doesn't work


I'm making an application with AngularJS & CakePHP.

I have one web service in Cake that might return data ordered but it doesn't do that, it returns data as came from DB.

This is part of my code:

     $this->Paginator->settings = array('limit' => 20, 'page' => $this->request->data['page']+1, 'recursive' => -1);
     $data = $this->Paginator->paginate('Country', $conditions, $order);

Anyone have an idea?


Solution

  • Here's the signature of Paginator's paginate component (See http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#custom-query-pagination):

    public function paginate(Model $model, $conditions, $fields, $order, $limit,
        $page = 1, $recursive = null, $extra = array())
    

    The second argument you should be passing is fields, not order.

    However, you can also just define the order in your settings array, like you do with a find condition.