Reputation: 31
In CakePHP 1.3 I could go to the last pagination page by adding the parameter page:last
.
I tried to use ?page=last
in CakePHP 3.0 but it does not work. How can I accomplish this?
Upvotes: 1
Views: 1469
Reputation: 4469
The functionality you mention was removed in CakePHP 2.0.
In CakePHP 3.x, to create a link from within the view, you can call
$this->Paginator->last($last = 'last >>', $options =[])
To obtain the last page from within a controller, you can access the following property:
$this->request->params['paging']['pageCount']
EDIT
A possible workaround to accept page:last
would be to add the following at the beginning of your action:
public function index() {
// detect page:last
if (!empty($this->request->params['named']['page'] && @$this->request->params['named']['page']=='last')) {
$this->Paginator->paginate();
$this->request->params['named']['page']=$this->request['paging'][$this->modelClass]['pageCount'];
}
//rest of code for action
$this->set('results', $this->Paginator->paginate());
}
You have to call $this->paginate()
twice, so it's not ideal.
lib/Cake/Controller/Component/PaginatorComponent.php
so that it supports page:last
. For further information, see
Upvotes: 2