/**
* Works with $this->builder to get the Compiled Select to operate on.
* Expects a GET variable (?page=2) that specifies the page of results
* to display.
*
* @param integer $perPage
* @param string $group Will be used by the pagination library
* to identify a unique pagination set.
* @param integer $page Optional page number (useful when the page number is provided in different way)
* @param integer $segment Optional URI segment number (if page number is provided by URI segment)
*
* @return array|null
*/
public function paginate(int $perPage = null, string $group = 'default', int $page = null, int $segment = 0)
{
$pager = \Config\Services::pager(null, null, false);
if ($segment)
{
$pager->setSegment($segment);
}
$page = $page >= 1 ? $page : $pager->getCurrentPage($group);
$total = $this->countAllResults(false);
// Store it in the Pager library so it can be
// paginated in the views.
$this->pager = $pager->store($group, $page, $perPage, $total, $segment);
$perPage = $this->pager->getPerPage($group);
$offset = ($page - 1) * $perPage;
return $this->findAll($perPage, $offset);
}