Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Pagination uri_segment hard coded to 3? #1476
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->pagination->initialize($config); $this->pagination->create_links();
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.
$config['base_url'] = site_url('controller/function/param1'); $this->pagination->initialize($config); $this->pagination->create_links();
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:
After adding this line the links correctly pulled the current page.
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.
The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it.