How to start with pagination class in codeigniter?

by muriel.schmidt , in category: PHP Frameworks , 23 days ago

How to start with pagination class in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 22 days ago

@muriel.schmidt 

To start using the pagination class in CodeIgniter, follow these steps:

  1. Load the pagination library in your controller by adding the following line of code in the constructor:


$this->load->library('pagination');

  1. Set up the pagination configuration settings in your controller method where you want to display the paginated results. You can define these settings using an array like this:


$config['base_url'] = 'http://example.com/index.php/controller/method'; $config['total_rows'] = 100; $config['per_page'] = 10; $config['uri_segment'] = 3;


$this->pagination->initialize($config);

  1. Fetch the data to display with pagination and pass it to the view. You can also set the pagination links in the view using the create_links() method like this:


$data['results'] = $this->your_model->get_data($config['per_page'], $this->uri->segment(3)); $data['links'] = $this->pagination->create_links();


$this->load->view('your_view', $data);

  1. Create the view file (your_view.php) to display the paginated results and links. You can use the $results array to display the data and the $links variable to display the pagination links.


By following these steps, you can start using the pagination class in CodeIgniter to display paginated results for your data.