Seeing there is extensive support for CodeIgniter\RESTful\ResourceController and using models with pagination is the preferred way to go.
It seems a logical choice to add an option in the Pager class to return an array, which can be added to the output for a RESTful response.
Something along the lines of:
Code:
/**
* Creates an array with pagination details used to Rest Controllers
*/
public function ajaxLinks(string $group = 'default'): array
{
$this->ensureGroup($group);
$pager = new PagerRenderer($this->getDetails($group));
$pager->setSurroundCount(2);
$output = [];
$currentPage = null;
foreach ($pager->links() as $link) {
if ($link['active'])
$currentPage = $link['title'];
$output['pages'][] = ["page" => $link['title'], "active" => $link['active']];
}
if ($pager->hasPrevious()) {
$output['first'] = ["page" => $this->getFirstPage($group), "active" => (($currentPage == $this->getFirstPage($group)) ? true : false)];
}
if ($pager->hasNext()) {
$output['last'] = ["page" => $this->getLastPage($group), "active" => (($currentPage == $this->getLastPage($group)) ? true : false)];
}
$output['total'] = $this->groups[$group]['total'];
$output['pageCount'] = $this->groups[$group]['pageCount'];
return $output;
}