2012-09-19 41 views
0

請看看下面的代碼在一個名爲「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在查詢字符串中出現兩次)。

發生了什麼事?

+0

爲什麼不能ü嘗試'.htaccess'組織在''URL'的params'簡單的方法? – mrsrinivas

+0

查詢'per_page'由CodeIgniter添加,因爲您在base_url中使用'http_build_query',CodeIgniter每次都會追加per_page(即使它已經存在於URL中) – Philo

回答

0

添加URI段

$config['uri_segment'] = x ; 
+0

抱歉。你能進一步解釋嗎?這是爲了定義哪個URI段包含頁碼。我沒有使用URI段;我爲我的分頁使用查詢字符串。 – StackOverflowNewbie

+0

@StackOverflowNewbie:如果U使用'.htaccces'分配'$ config ['uri_segment']'3 ... – mrsrinivas