That should be possible, yes. First you need an appropriate route that makes use of an route element named page
, like:
Router::connect('/model/view/:page', [
'controller' => 'Models',
'action' => 'view'
]);
This is required, as the paginator helper will set the page number via a key named page
in the URL array when generating links. If you hadn't an element with that name in the route, the value would end in the query string. It is also important to not mark the page
element as to be passed, as otherwise the value would slip into the URL arrays that the paginator helper generates, and that wouldn't match your route anymore.
The other thing you'd need to do, would be to make sure that the paginator component has access to the requested page number. By default the component reads the value from either the request query string variables, or from the pagination options. So, in the controller for example you could do something like:
$page = $this->request->param('page');
if ($page !== null) {
$this->paginate['page'] = $page;
// or
$this->request->query['page'] = $page;
}
// ...
$result = $this->paginate();
For something more dry you could move this in a custom component, or an extended paginator component.
See also