請看看下面的代碼在一個名爲「test」控制器:CodeIgniter分頁配置錯誤?
$this->load->library('pagination');
// These 3 are the minimum config that needs to be set
$config['base_url'] = base_url() . 'test/?' . http_build_query($_GET, '', '&');
$config['total_rows'] = 173;
$config['per_page'] = 20;
// This returns something like this: ?name=foo/20
// I would expect something like this: ?name=foo&per_page=20
// $config['enable_query_strings'] = TRUE;
// This retuns something like this: ?name=foo&per_page=20 (which is what I want),
// but the documentation says it should be: ?c=test&m=index&per_page=20
$config['page_query_string'] = TRUE;
$this->pagination->initialize($config);
echo $this->pagination->create_links();
然後去:test/?name=foo
產生的分頁鏈接看起來是正確的。當你點擊鏈接號碼「2」時,你被重定向到?name=foo&per_page=20
,這是正確的。但是,創建的新分頁看起來不正確。它看起來像這樣:?name=foo&per_page=20&per_page=40
(per_page在查詢字符串中出現兩次)。
發生了什麼事?
爲什麼不能ü嘗試'.htaccess'組織在''URL'的params'簡單的方法? – mrsrinivas
查詢'per_page'由CodeIgniter添加,因爲您在base_url中使用'http_build_query',CodeIgniter每次都會追加per_page(即使它已經存在於URL中) – Philo