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/category/accessories/brand/sonia
http://mysite.com/our-products/browse/category/accessories/brand/sonia/range/dallas
http://mysite.com/our-products/browse/range/dallas
etc etc..
I am converting the uri segements into an array via
$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/category/accessories/brand/sonia/range/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/category/accessories/brand/sonia/range/dallas/10/20
http://mysite.com/our-products/browse/category/accessories/brand/sonia/range/dallas/10/20/30
http://mysite.com/our-products/browse/category/accessories/brand/sonia/range/dallas/10/20/30/40
etc etc.
Any ideas how to paginate this way?
Full controller method is
// load required libraries
$this->load->library("pagination");
//initalise search data array
$uri_search_data = $this->uri->uri_to_assoc(3);
//set status
$search_data['products.status'] = Product::STATUS_ACTIVE;
// check url to see if any of the following segment pairs are set
if(isset($uri_search_data['category']))
{
$search_data['product_categories.category_name'] = urldecode($uri_search_data['category']);
}
if(isset($search_data['brand']))
{
$search_data['product_brands.brand_name'] = urldecode($uri_search_data['brand']);
}
if(isset($search_data['range']))
{
$search_data['product_ranges.range_name'] = urldecode($uri_search_data['range']);
}
//get number of items per page limit
$limit = 12;
// new empty product object
$product = new Product();
// get pagination config array
$config = array();
$config["base_url"] = base_url('our-products/browse/' . $this->uri->assoc_to_uri($uri_search_data));
$config["total_rows"] = $product->count_records();
$config["per_page"] = $limit;
$this->pagination->initialize($config);
// get offset from uri defaulting to 0 if not present
$offset = end($this->uri->segment_array()) ? end($this->uri->segment_array()) : 0;
// get all products
$products = $product->get_where($search_data, $order = NULL, $limit, $offset);
// assign data to view
$this->view_data['pagination_links'] = $this->pagination->create_links();
$this->view_data['products'] = $products;
// load default template
$this->parser->parse('website/products/list.tpl', $this->view_data);
