2017-02-05 38 views
0

我有,當我按下一個子類,它加載其所有產品在類別,然後使用該索引作爲一個產品列表:CodeIgniter的分頁與指數函數

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

,因爲它可能含有很多產品,我使用CI的分頁庫。它工作得很好,當我去到第二或第三頁:

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

但是,當我返回到第一頁,它會失去子類的ID:

http://localhost/ClickBasket/listproductscontroller/index 

因此,的數據子頁面中的子類別及其產品無法找到。你如何解決這個問題?我仍然在學習CodeIgniter的分頁庫。

+0

請您分享您的控制器邏輯是什麼?你可以在控制器中處理它 – shafiq

回答

1

嘗試

我的代碼:

//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); 
+0

非常感謝你!但唯一真正缺少的是'reuse_query_string'配置。 –