Paginate model queries with paginate() and render navigation links with $pager->links() in views.
Pagination in CI4
// Model with pagination
$model = model(PostModel::class);
$posts = $model->paginate(10); // 10 per page
$pager = $model->pager;
return view("posts/index", ["posts" => $posts, "pager" => $pager]);
// In view
<?= $pager->links() ?>
<?= $pager->simpleLinks() ?>
// Custom pager template
// app/Views/Pager/my_pager.php
// In Config/Pager.php
public array $templates = [
"default_full" => "CodeIgniterPagerViewsdefault_full",
"my_full" => "AppViewsPagermy_pager",
];
$pager->links("default", "my_full");
// Manual pagination
$page = (int)($this->request->getVar("page") ?? 1);
$limit = 10;
$posts = $model->findAll($limit, ($page - 1) * $limit);