CodeIgniter allows to configure the link generated using and configuration array with given key value pairs. The complete documentation on the pagination library on what are the configurable elements are available at https://www.codeigniter.com/userguide3/libraries/config.html?highlight=config Here we will see how to use that for generating HTML markup for Bootstrap 4.
Create a new file named "pagination.php" in the application/config direcotry of the CodeIgniter framework installation. Include the following code in it.
<?php
$config['pagination_config'] = array(
'per_page' => '1',
'full_tag_open' => '<ul class="pagination">',
'full_tag_close' => '</ul>',
'num_tag_open' => '<li class="page-item"><span class="page-link">',
'num_tag_close' => '</span></li>',
'cur_tag_open' => '<li class="page-item active"><a class="page-link" href="#">',
'cur_tag_close' => '</a></li>',
'prev_tag_open' => '<li class="page-item"><span class="page-link">',
'prev_tag_close' => '</span></li>',
'next_tag_open' => '<li class="page-item"><span class="page-link">',
'next_tag_close' => '</span></li>',
'prev_link' => '<i class="icon-backward"></i>',
'next_link' => '<i class="icon-forward"></i>',
'last_tag_open' => '<li class="page-item"><span class="page-link">',
'last_tag_close' => '</span></li>',
'first_tag_open' => '<li class="page-item"><span class="page-link">',
'first_tag_close' => '</span></li>',
'suffix' => '.html');
?>
In the controller write the following code to load pagination library and the configuration from the configuration file.
<?php
$this->load->library('pagination');
$this->load->config('pagination');
$config = $this->config->item('pagination_config');
$config['base_url'] = $base_url;
$config['total_rows'] = 100; // Replace to dynamically pass actual result count
$this->pagination->initialize($config);
$data['content'] = 'view_name'; //template view in next step will load the view passed
$this->load->view('template', $data);
?>
In the view have the following code to generate and display the pagination link.
<?php
echo $this->pagination->create_links();
?>
This is end of this quick guide. However if you use our PHP Website Generator here then you don't need to worry about all these things as pagination is automatically generated with SEO friendly URL. You can configure number of items for page in the relevant action type when generating code.
Do you know that you can generate a complete PHP websites in minutes with PHP Website Generator?