[英]First link of pagination shows 404 page in CodeIgniter
我正在處理類別頁面的分頁。 我的路線是
$route['category/(:any)/(:num)'] = 'public_controller/category/$1';
而 url 到 go 到類別頁面是http://localhost/ecom/category/seats
但它顯示 404 錯誤頁面。 但是當我給http://localhost/ecom/category/seats/1
時,它工作正常,分頁也工作正常,第二個和第三個鏈接也工作,但是當我在分頁中單擊 1 時,它會出現 404 錯誤頁面。 我的 controller 代碼是
public function category($cat_slug = null,$offset = null){
$cat_id = $this->db->where('cat_slug',$cat_slug)->get('categories')->row_array();
$config['base_url'] = base_url() .'category/'.$cat_slug;
$config['total_rows'] = $this->db->where('cat_id',$cat_id['cat_id'])->count_all('products');
$config['per_page'] = 4;
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$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['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
$data['products'] = $this->public_model->category_page($cat_slug,$config['per_page'],$offset);
$id['cat_slug'] = $cat_slug;
$this->load->view('public_temp/header1');
$this->load->view('public_temp/left1',$id);
$this->load->view('public/category',$data);
$this->load->view('public_temp/footer1');
}
我可以嘗試什么來解決這個問題?
它顯示是因為您的router expect 2 parameter but you are giving 1 parameter seats
以這種方式定義您的路線
$route['category/(:any)/(:num)'] = 'public_controller/category/$1/$2';
現在調用您的路線http://localhost/ecom/category/seats/0
用於類別頁面http://localhost/ecom/category/seats/1
用於第一個分頁
如果你想分開你的類別路線Define two route one for category page and other for category pagination
對於類別頁面
$route['category/(:any)'] = 'public_controller/category/$1';
對於類別分頁
$route['category/(:any)/(:num)'] = 'public_controller/category/$1/$2';
所以,我為你的問題創建了一個演示,這對我有用↓↓
$route['category'] = 'my_controller/category'; // this route handles all the requests without any additional segments
$route['category/(:any)'] = 'my_controller/category/$1'; // this route handles the requests when only one segment is present
$route['category/(:any)/(:num)'] = 'my_controller/category/$1/$2'; // this route handles the requests when there are two segments(2nd parameter being a number)
這是可能的,因為
路由將按照它們定義的順序運行。 較高的路線總是優先於較低的路線。(參考)
我還發現了一個類似的問題,您可能想看看。
希望這能解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.