• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
two paginations on one controller

#1
[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 --->
$start_at = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
if ($this->uri->segment(3) == 'out') $start_at = 0;
$config['base_url'] = site_url('profile/messages/in');
// --- config: -------
$config['total_rows'] = $query->num_rows();
$config['uri_segment'] = 4;
$config['per_page'] = 1;
$config['full_tag_open'] = '<p style="padding: 3px 10px;">';
$config['full_tag_close'] = '</p>';
// --- get totals: ---
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
// ------------------&gt;
** that's for the INBOX


Code:
// --- pagination ---&gt;
$start_at = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
if ($this->uri->segment(3) == 'in') $start_at = 0;
$config['base_url'] = site_url('profile/messages/out');
// --- config: -------
$config['total_rows'] = $query->num_rows();
$config['uri_segment'] = 4;
$config['per_page'] = 1;
$config['full_tag_open'] = '<p style="padding: 3px 10px;">';
$config['full_tag_close'] = '</p>';
// --- get totals: ---
$this->pagination->initialize($config);
$data['out_pagination'] = $this->pagination->create_links();
// ------------------&gt;
** that's for the OUTBOX

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!

#2
[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;
}

#3
[eluser]xwero[/eluser]
Try this
Code:
// in common
$config['base_url'] = site_url('profile/messages');
// inbox
$config['uri_segment'] = 3;
// outbox
$config['uri_segment'] = 4;
It should give you a number for the inbox after the messages segment and a number for the outbox after the inbox segment. I never did it myself so i don't know if it works.

#4
[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;
Easy, eh? Well not quite to get this to then work I had to write this nasty peice of code. Excuse the lack of any real explanation here, it's just a cut and past of the segment of code that I'm currently working on, so you'll have to peal away all the crap which is application specific. You'll get the jist tho - I'm using a dummy 7th URI segment set to zero, the 8th to actually carry the current page and the 6th to decide which object we are paginating. It's a mess. and it's quite possile that a load of this is not even neccessary - but I thought I'd leave something I've seen work, albeit as part of a larger program. I'm have two tables here - one displays only new messages, the other displays all messages - hence the names.

If anyone comes up with a more streamlines neat example of exactly what is needed, let me know,

Phil.

Code:
$allOffset=0;
        $newOffset=0;
        $newUri=7;
        $allUri=7;
        switch($this->uri->segment(6))
        {
            case "all":
                $allOffset=0+$this->uri->segment(8);
                $allUri=8;
                $this->npagConfig['cur_page'] = 0;
                break;
            case "new":
                $newOffset=0+$this->uri->segment(8);
                $newUri=8;
                $this->pagConfig['cur_page'] = 0;
                break;
            default:
                $newUri=8;
                $allUri=8;    
                $this->pagConfig['cur_page'] = $this->npagConfig['cur_page'] = 0;
                break;
        }
        

        $this->pagConfig['uri_segment'] = $allUri;
        $this->pagConfig['base_url'] = base_url()."index.php/messages/allmessages/index/$this->messageType/$this->cycleId/all/0";
        $this->pagConfig['total_rows'] = $this->messages_model->numActions($this->cycleId,$this->messageType);
        $this->pagination->initialize($this->pagConfig);
        $this->data['allPageLink']= $this->pagination->create_links();

        $this->npagConfig['per_page'] = '1';
        $this->npagConfig['full_tag_open'] = '<p>';
        $this->npagConfig['full_tag_close'] = '</p>';

        $this->npagConfig['uri_segment'] = $newUri;
        $this->npagConfig['base_url'] = base_url()."index.php/messages/allmessages/index/$this->messageType/$this->cycleId/new/0";
        $this->npagConfig['total_rows'] = $this->messages_model->numErrors($this->cycleId);
        $this->pagination->initialize($this->npagConfig);
        $this->data['newPageLink']= $this->pagination->create_links();

#5
[eluser]falloutphil[/eluser]
[quote author="xwero" date="1204519671"]Try this
Code:
// in common
$config['base_url'] = site_url('profile/messages');
// inbox
$config['uri_segment'] = 3;
// outbox
$config['uri_segment'] = 4;
It should give you a number for the inbox after the messages segment and a number for the outbox after the inbox segment. I never did it myself so i don't know if it works.[/quote]


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.

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

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

Phil.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.