Question

In CakePHP, I would like to sort my index list (created by the paginator component) on sequence ASC, but it won't work. If I see the query setup in the CakePHP docs (http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#query-setup), my paginator settings should look like this:

public function index()
{
    $this->Paginator->settings = array(
        'Attraction' => array(
            'conditions' => array(
                'Attraction.deleted' => null
            ),
            'order' => array(
                'Attraction.sequence ASC',
                'Attraction.id ASC'
            ),
            'limit' => 15
        )
    );

    $attractions = $this->Paginator->paginate('Attraction');

    $this->set('attractions', $attractions);
}

But every time I load my index file, the list is sorted on ID and ignores the "order" setting. Can anybody tell me if there's anything wrong with my "order" item in my paginator settings? ;) Thx!

Was it helpful?

Solution

try

'order' => array(
     'Attraction.sequence' => 'asc',
     'Attraction.id' => 'asc'
),

edit:

The sorting direction must be in the array value, while the field name should be the index. The examles I found in the documentations are always showing that

OTHER TIPS

I don't think you should have that Attraction index in your options array - in other words, I think your options array should look like this:

$this->Paginator->settings = array(
     'conditions' => array(
         'Attraction.deleted' => null
     ),
     'order' => array(
         'Attraction.sequence ASC',
         'Attraction.id ASC'
     ),
    'limit' => 15
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top