Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pagination suffix doesn't work on previous links

Tags:

codeigniter

hi this in my pagination code

$config['base_url']    = base_url().'cp/orders/';
$config['suffix'] = '?'.http_build_query($_GET, '', "&");
$config['uri_segment'] = 3;
$config['total_rows']  = $count_all;
$config['per_page']    = 20 ;
$this->pagination->initialize($config);
echo $this->pagination->create_links();

so in the first page it works fine when i click on page2 it goes to

http://mysite.com/cp/orders/20?sort=id&adc=desc

but in the second page if i click on page one or previous page ( < ) it goes to

http://mysite.com/cp/orders/20

this

$config['suffix'] = '?'.http_build_query($_GET, '', "&");

doesn't work in the previous links!

like image 616
max Avatar asked Mar 05 '13 18:03

max


2 Answers

I found and fixed a bug that was related to the first page links being inconsistent with the rest of the page links. I'd suggest extending the Pagination library with the current version in the Github repo until CodeIgniter 3.0 is released, at which point it will be built-in and you can remove your extended lib.

The new version also has a config option called reuse_query_string, which when set to TRUE will keep any existing query strings. So if they are already present when you reach the page, you do not need to worry about specifying them as a suffix.

$config['reuse_query_string'] = TRUE;

Current library file: https://github.com/EllisLab/CodeIgniter/blob/develop/system/libraries/Pagination.php Related pull request with info: https://github.com/EllisLab/CodeIgniter/pull/2199

like image 66
Aken Roberts Avatar answered Sep 22 '22 17:09

Aken Roberts


You can set the first_url as following if you don't want to change the library:

$config['first_url'] = $config['base_url'] . $config['suffix'];
like image 23
Joe Cheng Avatar answered Sep 22 '22 17:09

Joe Cheng