Pagination & optional uri parameters |
[eluser]Adrian Walls[/eluser]
Hi, I have a method in my site to browse products by any combination of the following 3 criteria: category, brand or range. Any combination of these including none of them can be included when browsing. For example: http://mysite.com/our-products/browse http://mysite.com/our-products/browse/brand/sonia http://mysite.com/our-products/browse/ca...rand/sonia http://mysite.com/our-products/browse/ca...nge/dallas http://mysite.com/our-products/browse/range/dallas etc etc.. I am converting the uri segements into an array via Code: $this->uri->uri_to_assoc(3) My issue however is when it comes to pagination it always adds the offset to the end: http://mysite.com/our-products/browse/ca.../dallas/10 Therefore using uri_to_assoc means that the forth array entry has a key of 10 but no value. And when I build up the URL again for the pagination link I need to convert the uri segments array back into a url so I use assoc_to_uri however this then gives me http://mysite.com/our-products/browse/ca...llas/10/20 http://mysite.com/our-products/browse/ca...s/10/20/30 http://mysite.com/our-products/browse/ca...0/20/30/40 etc etc. Any ideas how to paginate this way? Full controller method is Code: // load required libraries
[eluser]Aken[/eluser]
A couple of options: 1) Add a faux "page" sort option to the end, before the pagination URL. Example: /browse/category/accessories/brand/sonia/range/dallas/page/10 2) I can't promise this is the best solution (depends on a few variables), but you could check the total number of URI segments using $this->uri->total_segments(). If it's odd, you know an extra has been stuck on the end, and you can remove it. Either way, you'll want to sanitize the base_url option of your pagination to make sure that the pagination number is not included. Should be easy. |
Welcome Guest, Not a member yet? Register Sign In |