Welcome Guest, Not a member yet? Register   Sign In
[Solved] Query String Not Staying In Pagination URL
#4

(06-05-2015, 08:11 AM)mwhitney Wrote: Ever since I stopped using them, query strings make my head hurt, but this setting in the pagination config might help fix your problem:
Code:
$config['reuse_query_string'] = true;

Hi, I got it to work.

Any changes you would recommend The model function on controller just in there temporary


PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Example extends MX_Controller {

    public function 
__construct() {
 
       parent:: __construct();
 
       $this->load->library("pagination");
 
   }

    public function 
index() {
        
$data['title'] = "Example Codeigniter Pagination";

        
$get_sort $this->input->get('sort');

 
       if (isset($get_sort)) {
            
$sort $get_sort;
        } else {
            
$sort 'example_id';
        }

        
$get_order $this->input->get('order');

        if (isset(
$get_order)) {
            
$order $get_order;
        } else {
            
$order 'asc';
        }

        
$get_pagesize $this->input->get('pagesize');

        if (isset(
$get_pagesize)) {
            
$pagesize $get_pagesize;
        } else {
            
$pagesize 10;
        }

        
$data['limits'] = array();

        
$limits array_unique(array(102030405060708090100));

        
sort($limits);

        foreach(
$limits as $value) {
            
$data['limits'][] = array(
                
'text' => $value,
                
'value' => $value,
                
'href'  => base_url() .'example' .'/?&pagesize='$value
            
);
        }

 
       $config["base_url"] = base_url('example');
 
       $config["total_rows"] = $this->record_count();
 
       $config["per_page"] = $pagesize;
 
       $config['page_query_string'] = TRUE;
 
       $config['reuse_query_string'] = true;

 
       $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'] = '&laquo';
        
$config['prev_tag_open'] = '<li class="prev">';
        
$config['prev_tag_close'] = '</li>';
        
$config['next_link'] = '&raquo';
        
$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);

 
       $offset = ($this->input->get('per_page')) ? $this->input->get('per_page') : 0;

 
       $data['results'] = array();
 
       $data["results"] = $this->get_examples($config["per_page"], $offset);
 
       $data["links"] = $this->pagination->create_links();

 
       $url '';

 
       if ($order == 'asc') {
            
$url .= '&order=desc';
        } else {
            
$url .= '&order=asc';
        }

        if (
$this->input->get('pagesize')) {
            
$data['example_id'] = base_url('example') . '/?&sort=example_id' .$url'&pagesize=' .$this->input->get('pagesize');
            
$data['example_name'] = base_url('example') . '/?&sort=example_name' .$url'&pagesize=' .$this->input->get('pagesize');
            
$data['example_date_added'] = base_url('example') . '/?&sort=example_date_added' .$url'&pagesize=' .$this->input->get('pagesize');
        } else {
            
$data['example_id'] = base_url('example') . '/?&sort=example_id' .$url;
            
$data['example_name'] = base_url('example') . '/?&sort=example_name' .$url;
            
$data['example_date_added'] = base_url('example') . '/?&sort=example_date_added' .$url;
        }

        
$url '';

        if (isset(
$get_sort)) {
            
$url .= '&sort=' $get_sort;
        }

        if (isset(
$get_order)) {
            
$url .= '&order=' $get_order;
        }

        
$data['pagesize'] = $pagesize;
        
$data['sort'] = $sort;
        
$data['order'] = $order;

        
$this->load->view('example_view'$data);
    }

    public function 
record_count() {
 
       return $this->db->count_all($this->db->dbprefix 'example');
 
   }

    public function 
get_examples($limit$offset) {
        
$this->db->limit($limit$offset);
        
$this->db->order_by($this->input->get('sort'), $this->input->get('order'));
 
       $query $this->db->get($this->db->dbprefix 'example');
 
 
       if ($query->num_rows() > 0) {
 
           foreach ($query->result_array() as $row) {
 
               $data[] = $row;
 
           }
 
           return $data;
 
       }
 
       return false;
    }


 

Attached Files
.php   Example.php (Size: 3.97 KB / Downloads: 280)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
RE: Query String Not Staying In Pagination URL - by wolfgang1983 - 06-05-2015, 06:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB