Set Peginaation in Searching in codeigniter
Controller Code:
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller {
function __construct() {
// Call the Model constructor
parent::__construct();
$this->load->helper('url');
$this->load->model('nj_user');
$this->load->library('session');
$username = $this->session->userdata('username');
if (empty($username)) {
redirect($this->config->base_url() . 'login');
}
$this->load->library('pagination');
}
public function index() {
redirect($this->config->base_url() . 'user/view');
}
//sarching
public function searchterm_handler($searchterm) {
if ($searchterm) {
$this->session->set_userdata('searchterm', $searchterm);
return $searchterm;
} elseif ($this->session->userdata('searchterm')) {
//print_r ($_SESSION['searchterm']);exit;
$searchterm = $this->session->userdata('searchterm');
return $searchterm;
} else {
$searchterm = '';
return $searchterm;
}
}
public function searh()
{
$this->load->view('layout/header');
$this->load->view('layout/sidebar');
//pagination//
$searchterm = $this->searchterm_handler($_POST, TRUE);
$config = array();
$config['base_url'] = $this->config->base_url() . 'user/searh';
$config['total_rows'] = $this->nj_user->count_search($searchterm);
$config['per_page'] = 3;
$config['uri_segment'] = 3;
$choice = $config['total_rows'] / $config['per_page'];
$config['num_links'] = round($choice);
//config for bootstrap pagination class integration
$config['full_tag_open'] = '<ul class='pagination'>';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class='prev'>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class='active'> <a href='#'>';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
//searching... //
$data['result']= $this->nj_user->get_search($searchterm, $page, $config['per_page']);
//end searching...//
$data['link'] = $this->pagination->create_links();
$data['hms'] = $page;
$this->load->view('user/userview', $data);
$this->load->view('layout/footer');
}
}
?>
0 comments:
Post a Comment