wolfgang1983 Senior Member
Posts: 627
Threads: 271
Joined: Oct 2014
Reputation:
7
06-05-2015, 08:02 AM
(This post was last modified: 06-07-2015, 04:50 AM by wolfgang1983 .)
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_pag...agesize=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( 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 , 100 )); 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' ] = '«' ; $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 ); $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
Example.php (Size: 3.49 KB / Downloads: 232)
example_view.php (Size: 3.06 KB / Downloads: 203)
There's only one rule - please don't tell anyone to go and read the manual. Sometimes the manual just SUCKS!
wolfgang1983 Senior Member
Posts: 627
Threads: 271
Joined: Oct 2014
Reputation:
7
(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!
wolfgang1983 Senior Member
Posts: 627
Threads: 271
Joined: Oct 2014
Reputation:
7
(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( 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 , 100 )); 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' ] = '«' ; $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 ); $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
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!