public function paginate(?int
$perPage = null, string
$group = 'default', ?int
$page = null, int
$segment = 0
) { // Since multiple models may use the Pager, the Pager must be shared.
$pager = Services::
pager();
if ($segment) { $pager->
setSegment($segment,
$group);
} $page =
$page >= 1 ?
$page :
$pager->
getCurrentPage($group);
// Store it in the Pager library, so it can be paginated in the views.
$this->pager =
$pager->
store($group,
$page,
$perPage,
$this->
countAllResults(false
),
$segment);
$perPage =
$this->pager->
getPerPage($group);
$offset =
($pager->
getCurrentPage($group) - 1
) *
$perPage;
return $this->
findAll($perPage,
$offset);
} /**
* It could be used when you have to change default or override current allowed fields.
*
* @param array $allowedFields Array with names of fields
*
* @return $this
*/