New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination uri_segment hard coded to 3? #1476

Closed
ghost opened this Issue Jun 13, 2012 · 3 comments

Comments

Projects
None yet
3 participants
@ghost

ghost commented Jun 13, 2012

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.

Example (broken):

$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:

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

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

@alexbilbie

This comment has been minimized.

Show comment
Hide comment
@alexbilbie

alexbilbie Jun 14, 2012

Contributor

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

Contributor

alexbilbie commented Jun 14, 2012

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

@vkeranov

This comment has been minimized.

Show comment
Hide comment
@vkeranov

vkeranov Jun 18, 2012

Contributor

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.

Contributor

vkeranov commented Jun 18, 2012

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.

narfbg added a commit that referenced this issue Oct 22, 2012

@narfbg

This comment has been minimized.

Show comment
Hide comment
@narfbg

narfbg Oct 22, 2012

Contributor

See the above commit.

Contributor

narfbg commented Oct 22, 2012

See the above commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment