문제

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!

도움이 되었습니까?

해결책

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

다른 팁

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
);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top