0
votes

I'm using paginator component of paramType is querystring, and specified multiple order in action before taking results from $this->paginate() as like this

$this->paginate['order'] = array(
    "field1" => "Asc",
    "field2" => "Desc",
    "field3" => "Asc",
);

$this->set('results', $this->paginate('ModelName'));

When i click on page 2 link it's generating a url like ?page=2&sort=field1&direction=Asc I want to remove the sort key from query strings and need to fetch the results by applying order i've specified.

Could anybody help me on this ?

Thanks

1
We might have to backport github.com/cakephp/cakephp/pull/2753 into 2.5mark
Does it support multiple sorting @mark ?Anil kumar

1 Answers

-2
votes

As seen on documentation, you can override the paginate method:

/**
 * Overridden paginate method - group by week, away_team_id and home_team_id
 */
public function paginate($conditions, $fields, $order, $limit, $page = 1,
    $recursive = null, $extra = array()) {

    $recursive = -1;
    $group = $fields = array('week', 'away_team_id', 'home_team_id');
    return $this->find(
        'all',
        compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive', 'group')
    );
}

Or this, taken from documentation:

Control which fields used for ordering
By default sorting can be done with any column on a model. This is sometimes undesirable as it can allow users to sort on un-indexed columns, or virtual fields that can be expensive to calculate. You can use the 3rd parameter of PaginatorComponent::paginate() to restrict the columns that sorting will be done on:

$this->Paginator->paginate('Post', array(), array('title', 'slug'));

This would allow sorting on the title and slug columns only. A user that sets sort to any other value will be ignored.



http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html