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

[eluser]falloutphil[/eluser]
Code Igniter 1.6.1

Don't want to cross post so see:
http://ellislab.com/forums/viewthread/73039/

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:

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

Phil.
#2

[eluser]xwero[/eluser]
where does the $uri_page_number comes from?
#3

[eluser]xwero[/eluser]
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
Code:
// controller
$this->load->library('pagination');

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

$this->pagination->initialize($config);

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

[eluser]falloutphil[/eluser]
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:

Code:
// 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.

Phil.
#5

[eluser]xwero[/eluser]
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.
#6

[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.
#7

[eluser]falloutphil[/eluser]
I've posted code to extend CI to handle this more gracefully.

http://ellislab.com/forums/viewthread/73728/

Phil.




Theme © iAndrew 2016 - Forum software by © MyBB