Skip to content
This repository

Pagination uri_segment hard coded to 3? #1476

schwanz opened this Issue June 13, 2012 · 3 comments

4 participants

schwanz Andrey Andreev Alex Bilbie vkeranov

In the built-in pagination class (libraries/Pagination.php) the variable $uri_segment is hard coded to a value of 3. This is normally the segment of the uri that contains the current page (so the links can format properly), but if you set a base_url with more than 2 segments the links created no longer function correctly.

Example (works as expected):

$config['base_url'] = site_url('controller/function');

This produces the links which correctly highlight the current page, move correctly from previous to next, etc, since the uri_segment for 3 would be the generated page number. (controller/function/[page inserted by pagination]). If you add on another segment to the base_url, however, the uri_segment is no longer 3, but some larger value.

Example (broken):

$config['base_url'] = site_url('controller/function/param1');

The current page is at a uri_segment of 4 now, not 3. So if you click on page 2, for example, it correctly generates the link (controller/function/param1/[page inserted by pagination], but the current page is no longer displayed correctly. This limitation forces any function using pagination to not have any parameters when enable_query_strings is not set, which is annoying.

Simple fix which worked for me, but probably would not for all cases:

$this->uri_segment = count(explode("/", $CI->uri->uri_string())); // assumes no trailing slash

After adding this line the links correctly pulled the current page.

Alex Bilbie

I've encountered this too. I'll work on a fix later today.


The default is set to 3, but I don't see what is the problem, as you can change it... Please, read the user guide (quote):

The following is a list of all the preferences you can pass to the initialization function to tailor the display.
$config['uri_segment'] = 3;

The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it.

Andrey Andreev narfbg referenced this issue from a commit October 22, 2012
Andrey Andreev Fix issues #1476, #1909 e66d624
Andrey Andreev

See the above commit.

Andrey Andreev narfbg closed this October 22, 2012
Michael Zimmer nonchip referenced this issue from a commit in nonchip/CodeIgniter October 22, 2012
Andrey Andreev Fix issues #1476, #1909 e696423
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.