2012-05-08 55 views
2

我試着通過分頁DB返回的結果。但是,當我嘗試從URI偏移:Pagnation用GET數據在URI - 笨

questions/search?content=foobar/4

/4應該補償,但被分配到$_GET值。

這是在控制器的整個方法:

http://pastebin.com/QFJddMDJ

$results = $this->question->search_results_count($content); 
$this->load->library('pagination'); 
$config['total_rows'] = count($results); 
$offset = $this->uri->segment(3); 
if ($offset == false) $offset = 0; 
$config['full_tag_open'] = '<ul class="pages">'; 
$config['full_tag_close'] = '</ul>'; 
$config['num_tag_open'] = '<li>'; 
$config['num_tag_close'] = '</li>'; 
$config['cur_tag_open'] = '<li><a class="active">'; 
$config['cur_tag_close'] = '</a></li>'; 
$config['prev_tag_open'] = '<li class="prev">'; 
$config['prev_tag_close'] = '<li>'; 
$config['next_tag_open'] = '<li class="next">'; 
$config['next_tag_close'] = '</li>'; 
$config['num_tag_open'] = '<li>'; 
$config['num_tag_close'] = '</li>'; 
$config['first_link'] = '<<'; 
$config['first_tag_open'] = '<li>'; 
$config['first_tag_close'] = '</li>'; 
$config['last_link'] = '>>'; 
$config['last_tag_open'] = '<li>'; 
$config['last_tag_close'] = '</li>'; 
$config['per_page'] = 1; 
$config['uri_segment'] = 2; 
$config['page_query_string'] = TRUE; 
$config['use_page_numbers'] = TRUE; 
$config['suffix'] = '?content='.$content; 
$config['base_url'] = base_url().'questions/search/'; 
$this->pagination->initialize($config); 
+0

查詢字符串必須在你的URL的最後一件事。類似於/ search/4?content = foo的作品? –

+0

如何在配置中查看base_url? –

+0

看着你的config/config.php文件和條目,上面寫着$配置['BASE_URL] = XXXXXX; –

回答

12

正如我敢肯定你知道,URI是不會這樣的工作。查詢字符串必須位於末尾(或在#散列片段之前)。此查詢字符串:

questions/search?content=foobar/4 

手段$_GET['content'] = 'foobar/4';

您需要更改您的分頁的網址是這樣的:

questions/search/4/?content=foobar 

4後/還有可選的。

你必須從你的分頁的$config['base_url']刪除查詢字符串,而是其附加到視圖,其可悲的是涉及入侵的分頁類的鏈接...

或者試試這個無證功能:

// After loading the pagination class 
$this->pagination->suffix = '{YOUR QUERY STRING}'; 

或者更好的,只是加載類前添加$config['suffix'] = '{YOUR QUERY STRING}';到你的配置。這應該會自動將查詢字符串添加到每個鏈接的href

一些調整,以您的配置區域還需要:

// Make sure to encode these 
// $config['first_link'] = '<<'; 
$config['first_link'] = '&lt;&lt;'; 
// $config['last_link'] = '>>'; 
$config['last_link'] = '&gt;&gt;'; 

$offset = $this->uri->segment(3); 
// Default URI segment is 3, and it's what you use above. Remove this. 
// $config['uri_segment'] = 2; 

// This should be FALSE (default). Remove it. 
// $config['page_query_string'] = TRUE; 

// This should be FALSE (default) if you're 
// using the URI segment as your OFFSET. Remove it. 
// $config['use_page_numbers'] = TRUE; 

// Add your query string 
$config['suffix'] = '?content='.$content; 
$config['base_url'] = base_url().'questions/search/'; 
$this->pagination->initialize($config); 
+1

類似'?content = foobar'。無論你想在頁面編號後出現在href中。 –

+0

我做了這樣的事:'$配置[「後綴」] = $內容;'但是當我create_links()輸出爲空字符串「內容=?」。 –

+1

您是否記得'echo'?...編輯您的問題並將您的完整代碼添加到您的帖子中,然後我會查看它。 –