Hi! Since the manual numbering of pages in the method $ pager->makeLinks ($page, $perPage,
$total) is
$total,
I propose to change the paginate method in the System/Model.php:
PHP Code:
public function paginate(int $perPage = 20, string $group = 'default', int $page = 0,bool return_with_total = false)
{
// Get the necessary parts.
$page = $page >= 1 ? $page : (ctype_digit($_GET['page'] ?? '') && $_GET['page'] > 1 ? $_GET['page'] : 1);
$total = $this->countAllResults(false);
// Store it in the Pager library so it can be
// paginated in the views.
$pager = \Config\Services::pager();
$this->pager = $pager->store($group, $page, $perPage, $total);
$offset = ($page - 1) * $perPage;
if(return_with_total)return ['total'=>$total,'table' => $this->findAll($perPage, $offset)]; // Add
return $this->findAll($perPage, $offset);
}
This will avoid unnecessary duplicate requests.
Code:
2019-05-25T08:55:27.306774Z 33 Query SELECT COUNT(*) AS `numrows`
FROM `customer`
WHERE `id` IN (1,2,3,4,5)
AND `name` LIKE '%test%'
2019-05-25T08:55:27.307196Z 33 Query SELECT COUNT(*) AS `numrows`
FROM `customer`
WHERE `id` IN (1,2,3,4,5)
AND `name` LIKE '%test%'
2019-05-25T08:55:27.309970Z 33 Query SELECT *
FROM `customer`
WHERE `id` IN (1,2,3,4,5)
AND `name` LIKE '%test%'
ORDER BY `id` ASC
LIMIT 10
2019-05-25T08:55:27.324738Z 33 Quit