Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Code

By: a guest on Oct 5th, 2012  |  syntax: PHP  |  size: 1.92 KB  |  views: 43  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  // load required libraries
  2.  $this->load->library("pagination");
  3.        
  4.  //initalise search data array
  5.  $uri_search_data = $this->uri->uri_to_assoc(3);
  6.  
  7.         //set status
  8.         $search_data['products.status'] = Product::STATUS_ACTIVE;
  9.        
  10.         // check url to see if any of the following segment pairs are set
  11.         if(isset($uri_search_data['category']))
  12.         {
  13.            $search_data['product_categories.category_name'] = urldecode($uri_search_data['category']);        
  14.         }        
  15.         if(isset($search_data['brand']))
  16.         {
  17.            $search_data['product_brands.brand_name'] = urldecode($uri_search_data['brand']);
  18.         }
  19.         if(isset($search_data['range']))
  20.         {
  21.            $search_data['product_ranges.range_name'] = urldecode($uri_search_data['range']);          
  22.         }
  23.                
  24.         //get number of items per page limit
  25.         $limit = 12;
  26.                
  27.         // new empty product object
  28.         $product = new Product();
  29.        
  30.         // get pagination config array
  31.         $config = array();
  32.         $config["base_url"] = base_url('our-products/browse/' . $this->uri->assoc_to_uri($uri_search_data));
  33.         $config["total_rows"] = $product->count_records();
  34.         $config["per_page"] = $limit;
  35.         $this->pagination->initialize($config);
  36.  
  37.         // get offset from uri defaulting to 0 if not present
  38.         $offset = end($this->uri->segment_array()) ? end($this->uri->segment_array()) : 0;
  39.                        
  40.         // get all products
  41.         $products = $product->get_where($search_data, $order = NULL, $limit, $offset);
  42.                
  43.         // assign data to view
  44.         $this->view_data['pagination_links'] = $this->pagination->create_links();
  45.         $this->view_data['products'] = $products;
  46.        
  47.         // load default template
  48.         $this->parser->parse('website/products/list.tpl', $this->view_data);