• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Query String Not Staying In Pagination URL

#1
On my codeigniter pagination I am trying to get my page size query string in url to stay when I click on my pagination button links.

Pagesize is created when I select a from a dropdown menu.

When a page size is selected creates url like so

http://localhost/project/example/?&pagesize=10

But when I click on my pagination button like lets say my second link it makes url like but does not show pagesize.

http://localhost/project/example?per_page=10

When I click on pagination button I would like it to look like

http://localhost/project/example?per_page=10&pagesize=10

Question If page size is selected how can I make it show when I click on a pagination link after perpage

Any Suggestion


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['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';
    }

    
$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);
 
  }


Routes


PHP Code:
$route['example'] = "example/index";
$route['example/(:any)'] = "example/index/$1";
$route['example/(:any)/(:any)'] = "example/index/$1/$2";
$route['example/(:any)/(:any)/(:any)'] = "example/index/$1/$2/$3";
$route['example/(:any)/(:any)/(:any)/(:any)'] = "example/index/$1/$2/$3/$4"


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

#2
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;
Reply

#3
(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;

Thanks will give it ago in morning will inform you.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#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: 279)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#5
Hi,
This kind of custom routing did'nt worked for me in my CMS, i used "_remap" instead.
NexoPOS 2.6.2 available on CodeCanyon.
Reply

#6
PHP Code:
$route['example'] = "example/index";
$route['example/(:any)'] = "example/index/$1";

// The below will never run, any is a catch all root!

$route['example/(:any)/(:any)'] = "example/index/$1/$2";
$route['example/(:any)/(:any)/(:any)'] = "example/index/$1/$2/$3";
$route['example/(:any)/(:any)/(:any)/(:any)'] = "example/index/$1/$2/$3/$4"
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#7
As stated in the docs, (:any) becomes [^/]+, so it only matches a segment, so those other routes are needed if you wish to pass multiple arguments to the index method. However, I'm not sure whether this matters when you're using query strings instead of passing arguments to the controller method.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.