CodeIgniter Forums
How to append data to pagination links? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How to append data to pagination links? (/thread-47594.html)



How to append data to pagination links? - El Forum - 12-14-2011

[eluser]machouinard[/eluser]
I'm working with an image gallery.
In the view, there is a checkbox to display a preview of the comments for photos beneath the thumbnails. By default comment previews are not shown, and the checkbox is not selected.

User can check the display comments box, select an album and/or category to display images and the request is POSTed back to the controller.

Controller checks for 'comments' in POST (along with album and category).
if it is set, it sets session->userdata('comments') = 1
if it is not set, it unsets session->userdata('comments')

The View displays the comment preview if session->userdata('comments') is set.
The View displays the checkbox as selected if session->userdata('comments') is set.
it displays the checkbox as not selected if session->userdata('comments') is not set.
This works fine until the user clicks a page link. Then the 'comments' is not set in the POST, the controller unsets session->userdata('post'), the comment previews are not displayed and the checkbox is no longer checked. Still with me?

I think the way to handle this is to have the controller check for 'comments' in the POST and in a URI segment, as right now it unsets session->userdata('comments') if it's not in POST. I would think something like
Code:
if($this->input->post('comments') == '1'  || $this->URI->segment(4) == 'true'){
           $this->session->set_userdata('comments', '1');
       }else{
           $this->session->unset_userdata('comments');
       }

Anyone have any thoughts about modifying the pagination library to append a simple true or false to the links it creates (based on session->userdata('comments')? Is there a simpler way to look at this?

Thanks much,
Mark