display()
public function display(array $pagination_data): void
Description
Renders pagination navigation controls with optional "Showing" statement. This method processes the pagination configuration through the model layer for validation, then outputs the complete pagination HTML. The method handles all link types - First, Previous, numbered pages, Next, and Last - with automatically detected or explicitly specified URL roots.
If the total number of records does not exceed the limit per page, the method returns early without rendering any output - no unnecessary markup.
Parameters
| Parameter | Type | Description | Default | Required |
|---|---|---|---|---|
| $pagination_data | array | An associative array of pagination configuration (see below). | ||
$pagination_data Keys
| Key | Type | Description | Default | Required |
|---|---|---|---|---|
| total_rows | int | The total number of records being paginated. | N/A | Yes |
| limit | int | The number of records to display per page. | N/A | Yes |
| record_name_plural | string | The plural name for the records (e.g., 'products', 'articles') used in the showing statement. | N/A | Yes |
| include_showing_statement | bool | Whether to display a "Showing X to Y of Z records" statement above the pagination links. | false | No |
| page_num_segment | int|null | The URL segment containing the current page number. When null, the module auto-detects by checking if the last URL segment is numeric. |
null | No |
| pagination_root | string|null | The base URL path for pagination links. When null, the module auto-detects from the current URL. |
null | No |
| settings | array | Custom HTML wrapping for pagination links. Accepts keys such as pagination_open, pagination_close, cur_link_open, cur_link_close, num_link_open, num_link_close, first_link, last_link, prev_link, next_link, and their corresponding *_aria_label keys. |
[] | No |
| include_css | bool | Whether to include default pagination CSS styling. | false | No |
| showing_statement | string|null | A custom showing statement template. Use {start}, {end}, and {total} as placeholders for dynamic values. |
null | No |
| num_links_per_page | int | The maximum number of page number links to display at once. | 7 | No |
Return Value
| Type | Description |
|---|---|
| void | This method does not return a value. It outputs the pagination HTML directly. |
Example #1
Basic usage - paginate blog posts with 10 per page and display a showing statement.
public function index(): void {
$sql = 'SELECT * FROM blog_posts ORDER BY date_created DESC';
$total_rows = $this->db->query($sql, ['count'])->total;
$limit = 10;
$offset = (segment(2, 'int') - 1) * $limit;
$data['body'] = $this->db->query($sql . " LIMIT $limit OFFSET $offset", ['result']);
$pagination_data['total_rows'] = $total_rows;
$pagination_data['limit'] = $limit;
$pagination_data['record_name_plural'] = 'blog posts';
$pagination_data['include_showing_statement'] = true;
$data['pagination'] = $this->pagination->display($pagination_data);
$this->templates->public($data);
}Example #2
Using a custom showing statement with placeholders and custom HTML settings for styling.
$pagination_data['total_rows'] = 256;
$pagination_data['limit'] = 20;
$pagination_data['record_name_plural'] = 'products';
$pagination_data['include_showing_statement'] = true;
$pagination_data['showing_statement'] = 'Viewing {start}-{end} of {total} products';
$pagination_data['num_links_per_page'] = 5;
$pagination_data['settings']['pagination_open'] = '<nav class="my-pagination">';
$pagination_data['settings']['pagination_close'] = '</nav>';
$pagination_data['settings']['cur_link_open'] = '<span class="active">';
$pagination_data['settings']['cur_link_close'] = '</span>';
$pagination_data['settings']['first_link'] = '« First';
$pagination_data['settings']['last_link'] = 'Last »';
$this->pagination->display($pagination_data);Example #3
Auto-detected pagination - the module determines the current page and pagination root from the URL automatically.
$pagination_data['total_rows'] = 1200;
$pagination_data['limit'] = 15;
$pagination_data['record_name_plural'] = 'images';
$pagination_data['include_showing_statement'] = true;
$this->pagination->display($pagination_data);