mrdaliri
mrdaliri

Reputation: 7338

how to change PaginatorHelper direction

how to change PaginatorHelper direction? it's generated links sort asc, and i want to change in to desc. i wrote that code at my .ctp file, but no changes..:

<?php $this->Paginator->options(array('direction' => 'desc')) ?>

how to change that direction? can I change it in controller? or i should change at view? my helpers:

public $helpers = array ('Html', 'Form', 'Paginator');

thanks.

Upvotes: 1

Views: 802

Answers (2)

Chuck Burgess
Chuck Burgess

Reputation: 11574

I know this is a late response, but I wanted to answer the question in case someone comes here looking for the correct answer as there has been no answers that are correct.

To change the default of the pagination direction in the paginator, there are two ways you can make this happen.

The Helper

If you are using the PaginatorHelper, you can set the default when you create the link in the view:

echo $this->Paginator->sort('Link Name', 'Model.columnName', array('direction' => 'desc')) ;

This will print the link that will sort the column based on the direction you identify in the options array as indicated above. If the options array is left out, it will default to 'asc'.

The Component

If you want to set the default direction on the PaginatorComponent, you do so like this:

$this->Paginator->settings = array(
    'direction' => 'desc',
    'sort' => 'Model.column',
);

Keep in mind this does two things. It will automatically sort your data by the Model.column identified in the sort option and it will do it in the direction specified.

NOTE: You cannot simply add the direction. It requires BOTH to be set in order to work.

Upvotes: 1

Dunhamzzz
Dunhamzzz

Reputation: 14798

Setting defaults for pagination is outlines in the documentation. You can also pass params to the paginate() call in your controller:

$this->paginate = array(
    'conditions' => array('Recipe.title LIKE' => 'a%'),
    'limit' => 10,
    'order' => 'Recipe.created'
);

Upvotes: 1

Related Questions