two paginations on one controller |
[eluser]A.M.F[/eluser]
hello, i want to make to pagnation for two controllers. i am showing a list of "sent items" and "recieved items" so for that i am making a pagination. this is how my pagination settings looks like: Code: // --- pagination ---> Code: // --- pagination ---> the problam is inside the create_links() function. when i click on a page in the INBOX, than the out_pagination also changes to this page and shows it. why? - if u didn't understand my explanation i will try to display it better thank u!
[eluser]falloutphil[/eluser]
Hi, I reckon this is because you're stilling sending the same URI segment to both paginators, even if you are handling what data is returned by your db query, CI's paginator still renders the links associated to BOTH objects using the same single peice of information. Looking at the paginator code I've pointed out this below. I've had a quick go at getting around the problem by modifying the URI segment the paginate works with depending upon another URI segment - i.e. have a uri segment that is permanently set to 0 and switch to this in your config if you want to view the other paginator. Frankly it's can of worms, and I didn't get it working very well. I'd suggest using create_links as a base, and rewriting it to handle your case. If you do get it working nicely - I'd be interested to know however! Hope this helps, Phil. // Determine the current page number. $CI =& get_instance(); if ($CI->uri->segment($this->uri_segment) != 0) <---- GOES WRONG HERE. { $this->cur_page = $CI->uri->segment($this->uri_segment); // Prep the current page - no funny business! $this->cur_page = (int) $this->cur_page; }
[eluser]xwero[/eluser]
Try this Code: // in common
[eluser]falloutphil[/eluser]
OK - I couldn't put this down, I got very close to getting it working, so with a little more huffing and puffing I can now make it work.... it's not very pretty tho. First point - this is at least in part a Code Igniter 'bug' - CI doesn't leave the pagination object in a consistent state on exit. Normally this wouldn't matter - CI's pagination is stateless, so who cares if we mess up the internals of our object... we'll as we've both seen we do care if we want to make reuse of the pagination object. In short do this - Immediately before the return statment in create_links() in Pagination.php add this line - this will correctly reset the current page to be the same as before the funciton was run: Code: $this->cur_page = $uri_page_number; If anyone comes up with a more streamlines neat example of exactly what is needed, let me know, Phil. Code: $allOffset=0;
[eluser]falloutphil[/eluser]
[quote author="xwero" date="1204519671"]Try this Code: // in common As far as I can see this is not possible. CI's paginator expects the last URI to contain the pagination offset - if you give it a uri_segment of 4 but only have a base_url with 2 URIs in, CI just shortens this to 3 for you. It looks very tricky, if not impossible to me to carry two pagination URIs with CI's current implementation. Hence the use of an earlier URI to specify which object we are paginating in the other examples, and the other object being forced to it's first page. If anyone can show me a full blow example of storing state information for two paginations, I'll be impressed (and greatful!), Phil.
[eluser]falloutphil[/eluser]
I’ve posted code to extend CI to handle this more gracefully. http://ellislab.com/forums/viewthread/73728/ Phil. |
Welcome Guest, Not a member yet? Register Sign In |