Addition Of Codeigniter Pagination To Codefight CMS

Posted by Damodar Bashyal on March 21, 2009

 

Today I would like to archive my codeigniter pagination addition into my CMS.

My page entries were increasing gradually, so the page size was increasing and it didn't look too good to have multiple entries on the same page. So i thought now its time to add pagination. I had used pagination few years back when I was working at previous company 'visiontech digital media'. But i had totally forgotten by now. So checked the userguide and followed the process as:

frontend/config/pagination.php
<?php
//The number of links you want to show before and after of current page link
$config['num_links'] = 2;

//The opening tag placed on the left side of the entire result.
$config['full_tag_open'] = '<div class="page_numbers">';

//The closing tag placed on the right side of the entire result.
$config['full_tag_close'] = '</div>';

//The text you would like shown in the "first" link on the left.
$config['first_link'] = '« First';

//The opening tag for the "first" link.
$config['first_tag_open'] = '<div class="first">';

//The closing tag for the "first" link.
$config['first_tag_close'] = '</div>';

//The text you would like shown in the "last" link on the right.
$config['last_link'] = 'Last »';

//The opening tag for the "last" link.
$config['last_tag_open'] = '<div class="last">';

//The closing tag for the "last" link.
$config['last_tag_close'] = '</div>';

//The text you would like shown in the "next" page link.
$config['next_link'] = '>';

//The opening tag for the "next" link.
$config['next_tag_open'] = '<div class="next">';

//The closing tag for the "next" link.
$config['next_tag_close'] = '</div>';

//The text you would like shown in the "previous" page link.
$config['prev_link'] = '<';

//The opening tag for the "previous" link.
$config['prev_tag_open'] = '<div class="previous">';

//The closing tag for the "previous" link.
$config['prev_tag_close'] = '</div>';

//The opening tag for the "current" link.
$config['cur_tag_open'] = '<div class="current">';

//The closing tag for the "current" link.
$config['cur_tag_close'] = '</div>';

//The opening tag for the "digit" link.
$config['num_tag_open'] = '<div class="digit">';

//The closing tag for the "digit" link.
$config['num_tag_close'] = '</div>';
?>
frontend/controllers/page.php
<?php
$menu_id = $this->uri->segment(2, 1);

//On clicking more link of the page blurb show full text
$page_id = $this->uri->segment(3, 0);

//pagination
$page = $this->uri->segment(4, 0);

/*
 * START: Pagination config and initialization
 */
$this->load->library('pagination');
if(!$page_id) $page_id = 'home';

$config['base_url'] = base_url() . "page/$menu_id/$page_id/";
$config['total_rows'] = $this->page_model->get_page_count($menu_id);
$config['per_page'] = '5';
$config['uri_segment'] = 4;
$config['num_links'] = 2;
$this->pagination->initialize($config);
//END: Pagination

$data['pagination'] = $this->pagination->create_links();
//Get page content for the selected menu item.
$data = $this->page_model->get_page_contents($menu_id, $config['per_page'], $page);
?>
frontend/models/page_model.php
<?php
function get_page_count($menu_id = '0') {
	$this->db->where(array('menu_id' => $menu_id, 'pages_active' => '1'));
	return $this->db->count_all_results('pages');
}
function get_page_contents($menu_id = '0', $per_page = '5', $page = '0') {
	$this->db->join('pages_access', 'pages.pages_id = pages_access.pages_id');
	$this->db->order_by('pages.pages_sort', 'asc');
	$this->db->limit($per_page, $page);
	$query = $this->db->get_where('pages', array('pages.menu_id' => $menu_id, 'pages.pages_active' => '1'));
	$data1 = $query->result_array();
	
	$data = '';
	if(is_array($data1) && count($data1) > 0) {
		$data['meta'] = $this->meta_fetch($data1[0]);
		$data['content'] = $data1;
	} else {
		$data['meta'] = $this->defaults();
		$data['content'] = array();
	}
	return $data;
}
?>
frontend/views/page_view.php
<?php
if(isset($pagination)) echo $pagination;
?>

Thanks to godbit for better tutorial than codeigniter userguide.

 
not published on website


QR Code: Addition Of Codeigniter Pagination To Codefight CMS