Welcome Guest, Not a member yet? Register   Sign In
Change the paginate method
#1

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 20string $group 'default'int $page 0,bool return_with_total false)
    {
        
// Get the necessary parts.
        
$page $page >= $page : (ctype_digit($_GET['page'] ?? '') && $_GET['page'] > $_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
Reply


Messages In This Thread
Change the paginate method - by videoproc - 05-25-2019, 02:10 AM
RE: Change the paginate method - by sv3tli0 - 05-29-2019, 10:22 PM
RE: Change the paginate method - by videoproc - 05-30-2019, 11:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB