I'm banging my head on the keyboard, trying to figure out how to use the pagination query string, everything works fine until the FIRST link appears.
In all other links, the query string is added to the end, and the link is FIRST page misses the query string
Links for other pages:
http:
The link to the FIRST page shows the link that I set in the $config['base_url'] variable:
http://localhost/index.php/search/index/
Search Form:
$attributes=array('id'=>'search','class'=>'clearfix','method'=>'get'); echo form_open(base_url().'index.php/search/index',$attributes);
It has a text box with the name set to q .
I came across some answers / examples in stackoverflow, and here is what I wrote:
Pagination configuration file has
$config['per_page'] = '1'; $config['uri_segment'] = '3';
and others like num_tag_open etc.
Controller Class:
class Search extends CI_Controller { public function Search(){ parent::__construct(); $this->load->helper('url'); $this->load->helper('form'); $this->load->library('input'); $this->load->model('blog_model'); $this->load->library('pagination'); $this->config->load('pagination'); //other pagination related config variables } public function index($page=0){ $q = trim($this->input->get('q')); if(strlen($q)>0){ //validate input and show data $config['enable_query_strings']=TRUE; $getData = array('q'=>$q); $config['base_url'] = 'http://localhost/index.php/search/index/'; $config['suffix'] = '?'.http_build_query($getData,'',"&"); $data['rows'] = $this->blog_model->getBySearch($q,$this->config->item('per_page'),$page); if(empty($data['rows'])){ //no results found }else{ //match found $config['total_rows'] = $this->blog_model->getBySearchCount($q); $this->pagination->initialize($config); $link->linkBar = $this->pagination->create_links(); $this->load->view('myview',array($data,$link)); } }else if(strlen($q)==0){ //warn user for the missing query and show a searchbox } } }
SOS! Guys, please help me.
php get codeigniter pagination
Charanraj golla
source share