Welcome Guest, Not a member yet? Register   Sign In
Pagination with standard CI urls + query strings
#1

[eluser]skunkbad[/eluser]
I like to use query strings for searches. The reason for this is that I don't have the annoying browser messages when traveling backwards through history when POST is used. It was pretty easy to extend the Pagination class, and I wouldn't have even needed to extend the class if the $suffix class member was applied to ALL of the pagination links, but it isn't.

If it was, then I could have done something like this in my controller:

Code:
if( ! empty( $_SERVER["QUERY_STRING"] ) )
{
$config['suffix'] =  '?' . $_SERVER["QUERY_STRING"];
}

What do you think? Is there any good reason why the suffix shouldn't be appended to ALL of the links?
#2

[eluser]CroNiX[/eluser]
Hey Brian,

Hope things are good with ya.

Not having to do with the suffix question, but this might be of use to you:
https://github.com/CroNiX/CI-MY_URI-Segm...MY_URI.php

It kind of allow you to use "hybrid" query strings, like:
Code:
http://www.yoursite.com/users/list/page=5;limit=50;per_page=25
Where the 3rd segment is the hybrid query string. To get the data out of there you would:

Code:
$parameters = $this->uri->segment_to_assoc(3);
print_r($parameters);

//outputs
array(
  'page'     => 5,
  'limit'    => 50,
  'per_page' => 25
)
You just need to add the following 2 characters to your $config['permitted_uri_chars']: ';=', which are normally allowed anyway and shouldn't interfere with anything else.

It just doesn't use the question mark or ampersand in the "hybrid query string", but it allows you to stuff multiple parameters into a single segment. I use this for a custom pagination library and a few other things, and it's worked very well thus far. I just pass that segment and it does the rest.
#3

[eluser]skunkbad[/eluser]
Hey Steve,

Yeah, things are good here, with the exception of the standard Winter colds. How are you?

I like your idea, but what I was working on today was code that was already using $_GET, and I was just trying to find the most simple way of adding the query string back to the pagination links. $suffix isn't documented, so I felt free to change the way it was being used in the class. I'm applying the query string just as I showed above, and it works great. Tested it on my dev machine and testing site.

I just think it's weird that $suffix isn't applied to all of the links that are created. I wonder what the pagination class author had intended. I simply made sure all of the links were appended by $this->suffix, and it works great. Looking through the code, even the tip on github, I don't really understand how $suffix is supposed to be used. It seems to be applied differently for:

1) First link - not applied
2) Previous link - not always applied
3) Digit links - not always applied
4) Next link - always applied
5) Last link - always applied

What is going on here?





Theme © iAndrew 2016 - Forum software by © MyBB