Welcome Guest, Not a member yet? Register   Sign In
create_links() leaves Pagination object in inconsistent state

Code Igniter 1.6.1

Don't want to cross post so see:

Suggest fix is as follows. I guess this is only a bug if CI does not forbid more than one pagination per controller. So it's either a bug or an enhancement. Either way, it's a worthwhile modification. I've tested this locally, verified the problem and checked the solution works.

See post above to demonstrate the problem.

File: Pagination.php
Function: create_links()

Immediately before returning from the function add this line:

$this->cur_page = $uri_page_number;

Without this line attempts a >1 pagination fails as the current page is corrupted by the first pagination.

I don't believe this has been reported before, so if people agree I'll add this to the bug tracker.


where does the $uri_page_number comes from?

I did some checking in the validation code and i found there is no clear/reset function which could mean the people at Ellislab didn't foresee the use of multiple pagination links.

Maybe this can be fixed by using an identifier in the config array which makes it possible to define the link creation for the create_links method.

suggested code
// controller

$config['links1']['base_url'] = 'http://www.your-site.com/index.php/test/page/';
$config['links1']['total_rows'] = '200';
$config['links1']['per_page'] = '20';
$config['links1']['uri_segment'] = 3;

$config['links2']['base_url'] = 'http://www.your-site.com/index.php/test/page/';
$config['links2']['total_rows'] = '200';
$config['links2']['per_page'] = '20';
$config['links2']['uri_segment'] = 4;


// view
echo $this->pagination->create_links('links1');
echo $this->pagination->create_links('links2');

Sure - this may work. I accept that given no reset function 2 paginations is not explicitly supported - although if this is what Ellislab want they should prevent a second call to initalize() using a static counter.

To quote your example I think the problem will also occur if the user calls create_links more than once for the same pagination:

// view
echo $this->pagination->create_links('links1');
echo $this->pagination->create_links('links2');

The first create_links will alter the internal representation of cur_page, which will then break the second set of links. I believe this is within the realms of normal use.

The "reset" I've written simply makes use of the fact that the correct cur_page is stored earlier in the function before it is manipulated.


I've seen your code, sorry i didn't check it before, and i noticed there are two requirements for it to work
- different urls for the pagination links to the same page
- the create_links method can only be used in the controller
is this correct?

If you look at the example in the user guide you see they echo the create_links method so they suggest you use it in the view file. This is where i based my idea on.

I guess it's up to the people at Ellislab to decide if this is a bug or if there is room for improvement.

[eluser]Derek Allard[/eluser]
Originally pagination was only expected to have one set of links. That said, I don't object to more then one, but that currently isn't in there.

I've posted code to extend CI to handle this more gracefully.



Theme © iAndrew 2016 - Forum software by © MyBB