2011-10-18 20 views
0

我們已經在我們的配置如下設置一個CI安裝...分頁的笨,需要禁用查詢字符串,所以我們可以緩存

$config['enable_query_strings'] = TRUE; 

我們需要這個爲了我們的應用程序的其他區域使用第三方API正確運行。但是,發生的事情是,分頁是默認查詢字符串的分頁方法,這種方法在緩存方面效果不佳。

現在,他們這個樣子......

http://localhost/something/?&page=6 

它不與緩存打得不好,主要是因爲每個頁面的URL是相同的頁面CI。我的目標是切換到下面的示例,而不會干擾我的應用程序的其餘部分的全局設置。

我一直在嘗試了幾個小時,以找到一種方法,僅在這個應用程序的單一部分禁用上述設置,所以我們可以適當地有分頁,像這樣的獨立網址...

http://localhost/something/1 
http://localhost/something/2 
http://localhost/something/3 

到目前爲止,我一直無法覆蓋這個控制器的設置,說實話,我不知道甚至有一種方法來實際做到這一點。任何幫助表示讚賞。某種方式需要某種方法禁用單個控制器的功能。

+1

要獲得查詢字符串玩緩存不錯,在這裏看到: http://stackoverflow.com/questions/6194714/codeigniter-caching-issue-when-dealing-with-query-string-parameters – Thor

回答

2

您能用routing嗎?

$route['something/page/(:num)'] = "something?&page=$1"; 

編輯:關閉分頁查詢字符串與$config['enable_query_strings'] = TRUE;

系統/庫/ Pagination.php

〜線134

變化

if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) 
    { 
     if ($CI->input->get($this->query_string_segment) != 0) 
     { 
      $this->cur_page = $CI->input->get($this->query_string_segment); 

      // Prep the current page - no funny business! 
      $this->cur_page = (int) $this->cur_page; 
     } 
    } 
    else 
    { 
     if ($CI->uri->segment($this->uri_segment) != 0) 
     { 
      $this->cur_page = $CI->uri->segment($this->uri_segment); 

      // Prep the current page - no funny business! 
      $this->cur_page = (int) $this->cur_page; 
     } 
    } 

 if ($CI->uri->segment($this->uri_segment) != 0) 
     { 
      $this->cur_page = $CI->uri->segment($this->uri_segment); 

      // Prep the current page - no funny business! 
      $this->cur_page = (int) $this->cur_page; 
     } 

〜管線196

if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) 
    { 
     $this->base_url = rtrim($this->base_url).'&'.$this->query_string_segment.'='; 
    } 
    else 
    { 
     $this->base_url = rtrim($this->base_url, '/') .'/'; 
    } 

 $this->base_url = rtrim($this->base_url, '/') .'/'; 

可能做到這一點。或者,也許更好的形式將掛鉤到頁面...

+0

嗯,這是有趣的事情。我可以使用路由,如果它讓我爲分頁鏈接分配不同的鏈接結構。但據我從文檔中可以看出,它基於上面設置的$ config []被設置爲自動使用兩個鏈接示例中的任何一個。 –

+0

噢,我想我誤解了你的問題。你可以嘗試在135行左右的系統/庫/ Pagination.php中查詢字符串。註釋掉'if'查找全局query_string。以示例更新我的答案。 – stormdrain

2

簡單的解決方案...

$this->config->set_item('enable_query_strings',FALSE); 

只是把這個你打電話給分頁邏輯控制器之​​前。感謝您在#codeigniter IRC頻道中的Taftse中進行此簡單覆蓋。

相關問題