Skip to content

Instantly share code, notes, and snippets.

@rintoug
Created June 4, 2017 08:16
Show Gist options
  • Save rintoug/90298671e210eb95755325f110bb4aab to your computer and use it in GitHub Desktop.
Save rintoug/90298671e210eb95755325f110bb4aab to your computer and use it in GitHub Desktop.
How to do Pagination in CodeIgniter
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Country extends CI_Controller {
public function __construct()
{
parent:: __construct();
$this->load->model('Country_model', 'country');
$this->load->library("pagination");
}
public function listing()
{
$config = array();
$config["base_url"] = base_url() . "country/listing";
$config["total_rows"] = $this->country->total_rows();
$config["per_page"] = 20;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["countries"] = $this->country->get_countries($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view("listing", $data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment