Welcome Guest, Not a member yet? Register   Sign In
How can I use pagination without knowing the page segment
#1

[eluser]MyDarkPassenger[/eluser]
I'm using the pagination library. One problem I have with it is passing extra data into the links uri. Since pagination needs to know the segment that the page appears in, I can't change the amount of segments in the uri. So I have to pass longer uris like this:

http://localhost/test/main/index/sortby/.../all/page/

instead of cleaner, smaller ones like this.

http://localhost/test/main/index/sortby/name/page/

Is there a way to check for the segment using a name like page instead of a segment like 8. Also, if I need to use segments is there a way to modify the url used by pagination so that I can specify where the page segment can be added like:

"http://localhost/test/main/index/page/" . $page . "/sortby/name/";

This way I can always use segment 3 no matter how long the string is.
#2

[eluser]Aken[/eluser]
Sorry I can't provide a fully coded example, but this can definitely be done. It involves replacing/extending the pagination class and adding to or changing the code so that it works with page numbers instead of the offset number.

As for making sure it's the on the third URL segment each time, you should be able to do that using URI segments or routes. Again, I'm not in a position to go through example code. Sorry!
#3

[eluser]MyDarkPassenger[/eluser]
Appreciate the reply, I'll take a look through the code I could probably get it going but I figured someone probably had thought of this before and thrown something together.
#4

[eluser]jedd[/eluser]
Obviously it'd be easier to have consistent number of segments.

Could you just use 'nocat' and 'nosort' as placeholders for your two soon-to-be-fixed-in-space parameters there? That way your pagination offset will always be at the same spot?

This reduces the size of your URL in most cases (all except no category and no sort by selected).
#5

[eluser]MyDarkPassenger[/eluser]
Whether anybody wants it or not I wrote a quick helper that retrieves the segment id where the page is. If it doesn't exist it return 3, although this is rather insignificant it's only there so you have a number for page_segment. Don't know if anyone needs it but here it is:

function page_segment() {
$ci =& get_instance();
$temp = split_to_array($ci->uri->uri_string(), '/');
for($i=0;$i < count($temp);$i++) {
if ($temp[$i] == "page") return $i += 2;
}
return 3;
}

Basically I ended up saving the data in an array. I then through the array removing any element with a false value and then I convert it to a uri string appending it onto the links. I use some default values for the segments returned so if they don't exist I'm covered. So I have nice clean uris that I don't need to care where the page segment resides.




Theme © iAndrew 2016 - Forum software by © MyBB