0
votes

I have a list of products in which when I press on a subcategory, it loads all of its products in that subcategory and uses the index as:

http://localhost/ClickBasket/listproductscontroller/index?subcategory=4

Since it could contain a lot of products, I used CI's pagination library. It works well when I go to the second or third pages:

http://localhost/ClickBasket/listproductscontroller/index/1?subcategory=4
http://localhost/ClickBasket/listproductscontroller/index/2?subcategory=4

But when I return to the first page, it would lose the subcategory's id:

http://localhost/ClickBasket/listproductscontroller/index

As such, the data of the subcategory and its product in the page could not be found. How do you fix this? I am still learning about the pagination library of CodeIgniter.

1
could you please share your controller logic ? You can handle it in controller - shafiq.rst

1 Answers

1
votes

Try

My code:

//pagination
 $this->load->library('pagination');
 $config['base_url']   = site_url('/ClickBasket/listproductscontroller/index');
 $config['total_rows'] = $this->db->query('SELECT FOUND_ROWS() count;')->row()->count;
 $config['per_page']   = 9;
 #$config['uri_segment'] = 4;
 $config['full_tag_open']        = "<ul class='pagination'>";
 $config['full_tag_close']       = "</ul>";
 $config['num_tag_open']         = '<li>';
 $config['num_tag_close']        = '</li>';
 $config['cur_tag_open']         = "<li class='disabled'><li class='active'><a href='#'>";
 $config['cur_tag_close']        = "<span class='sr-only'></span></a></li>";
 $config['next_tag_open']        = "<li>";
 $config['next_tagl_close']      = "</li>";
 $config['prev_tag_open']        = "<li>";
 $config['prev_tagl_close']      = "</li>";
 $config['first_tag_open']       = "<li>";
 $config['first_tagl_close']     = "</li>";
 $config['last_tag_open']        = "<li>";
 $config['page_query_string']    = true;
 $config['query_string_segment'] = 'page';
 $config['reuse_query_string']   = true;
 $config['use_page_numbers']     = true;
 $config['last_tagl_close']      = "</li>";
 $this->pagination->initialize($config);