Friday, 5 October 2012

Pagination in Codeigniter


CodeIgniter’s Pagination class is very easy to use, and it is 100% customizable, either dynamically or via stored preferences.
Here is a simple example showing how to create pagination in one of your controller functions:

In the Controller page, just code like this :-
public function news(){
$this->load->helper('form');
$this->load->helper('url');
$data['urls']=base_url();
$data['news'] = $this->news_model->get_news();
$data['count']=count($data['news']);

$this->load->library('pagination');// loading the pagination library
$config['base_url'] = $data['urls'].'index.php/admin/news/';// configuring url to which page is located
$config['total_rows'] = $data['count'];// total count of records fetched
$config['per_page'] = 10; //count wanted per page
$this->pagination->initialize($config);// initializing the configs 
$data['pagelinks']= $this->pagination->create_links();//creating links

$this->load->view('templates/headermain',$data);
$this->load->view('admin/news',$data);
$this->load->view('templates/footermain');

}

then you have to just place te below code in view page to display the pagination:-
  <?php  echo $pagelinks; ?> 
your pagination comes like this :-



No comments:

Post a Comment