Skip to content

Commit 6f425c0

Browse files
committed
docs: improve sample code
1 parent c4109f7 commit 6f425c0

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎user_guide_src/source/libraries/pagination.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ Manual Pagination
9898

9999
You may find times where you just need to create pagination based on known data. You can create links manually
100100
with the ``makeLinks()`` method, which takes the current page, the number of results per page, and
101-
the total number of items as the first, second, and third parameters, respectively::
101+
the total number of items as the first, second, and third parameters, respectively:
102102

103-
<?= $pager->makeLinks($page, $perPage, $total) ?>
103+
.. literalinclude:: pagination/015.php
104104

105105
This will, by default, display the links in the normal manner, as a series of links, but you can change the display
106106
template used by passing in the name of the template as the fourth parameter. More details can be found in the following
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
use CodeIgniter\Controller;
6+
7+
class UserController extends Controller
8+
{
9+
public function index()
10+
{
11+
// ...
12+
13+
$pager = service('pager');
14+
15+
$page = (int) ($this->request->getGet('page') ?? 1);
16+
$perPage = 20;
17+
$total = 200;
18+
19+
// Call makeLinks() to make pagination links.
20+
$pager_links = $pager->makeLinks($page, $perPage, $total);
21+
22+
$data = [
23+
// ...
24+
'pager_links' => $pager_links,
25+
];
26+
27+
return view('users/index', $data);
28+
}
29+
}
30+
?>
31+
32+
<!-- In your view file: -->
33+
<?= $pager_links ?>

0 commit comments

Comments
 (0)