Cakephp 3 Pagination Routes
I am using CakePHP 3 and I want to paginate per user. However, when I click on the second page, the URL-address looks like /users?page=2
, and I expect: /users/2
.
I created this route in route.php:
$routes->connect('/users/:page', ['controller' => 'users', 'action' => 'index'], ['page' => '[0-9]+']);
And in Users / index.ctp, before the "prev" button, I'll put:
<?php
$this->Paginator->options([
'url' => [
'controller' => 'users',
'action' => 'index'
]
]);
?>
Now when I click on page 2 for example it /users/2
opens and I got this error message (RuntimeException):
Unable to locate an object compatible with paginate.
Am I missing something or have I made a mistake?
Thank you for your help.
source to share
PaginatorHelper built in url format, that is to use? page = n. It will also sort, for example, users? Page = 2 & sort = user_id & direction = asc. Your / users / {page} format does not handle sorting.
If your REALLY wants to stick with / users / {page} you will have to override PaginatorHelper.
source to share
try this from the side of your controller with a paginator component. This works for me
$this->Paginator->paginate('Users')
for custom url enter code here
u need to implement index action as
public function index($page = null){
$this->Paginator->settings = ['limit' => 15, 'page' => $page];
$this->set('users', $this->Paginator->paginate('Users'));
}
source to share