2013-06-12 143 views
1

我有一個項目正在進行,現在[管理部分幾乎完成](我知道一點晚了)我正試圖執行i18n到項目。 我認爲一切工作正常,除非我輸入http://localhost/my_project而my_project是工作目錄與CI安裝在其中,我重定向到以下http://localhost/my_project/enhome(沒有後en後的斜線)任何想法?Codeigniter國際化國際化i18n尾部斜槓沒有添加

預期結果http://localhost/my_project/en/home,而不僅僅是home控制器,但所有控制器都表現相同。

.htaccessbase_urlindex_page設置正確(所有的作品沒有i18n)。

routes.php文件超出編輯 的股票

$route['default_controller'] = "home"; 
$route['404_override'] = ''; 

// URI like '/en/about' -> use controller 'about' 
$route['^(en|de|fr|nl)/(.+)$'] = "$2"; 

// '/en', '/de', '/fr' and '/nl' URIs -> use default controller 
$route['^(en|de|fr|nl)$'] = $route['default_controller']; 

我使用 「新」 i18n從我猜ellislab。對不起,錯誤的鏈接(1.7 CI版本)。

+0

你是如何重定向它的?你可以發佈該代碼嗎? – Jeemusu

+0

我沒有重定向任何庫(i18n完成所有工作),而是在其他項目中使用它。但在這個問題上存在問題。 – Kyslik

回答

2

因此,經過一番挖掘,我發現核心文件中的問題,在此發佈的腳本的底部有變量$new_url,它沒有「修復」回顯Redirect triggered to http://192.168.1.184/my_project/enhome。我只是在那裏添加/,它工作正常,我不知道這裏發生了什麼,如果這是OK修復或不。

function MY_Lang() { 
    parent::__construct(); 

    global $CFG; 
    global $URI; 
    global $RTR; 


    $this->uri = $URI->uri_string(); 
    $this->default_uri = $RTR->default_controller; 

    $uri_segment = $this->get_uri_lang($this->uri); 
    $this->lang_code = $uri_segment['lang'] ; 

    $url_ok = false; 
    if ((!empty($this->lang_code)) && (array_key_exists($this->lang_code, $this->languages))) 
    { 
     $language = $this->languages[$this->lang_code]; 
     $CFG->set_item('language', $language); 
     $url_ok = true; 
    } 

    if ((!$url_ok) && (!$this->is_special($uri_segment['parts'][0]))) // special URI -> no redirect 
    { 
     // set default language 
     $CFG->set_item('language', $this->languages[$this->default_lang()]); 

     $uri = (!empty($this->uri)) ? $this->uri: $this->default_uri; 
     //OPB - modification to use i18n also without changing the .htaccess (without pretty url) 
     $index_url = empty($CFG->config['index_page']) ? '' : $CFG->config['index_page']."/"; 
     $new_url = $CFG->config['base_url'].$index_url.$this->default_lang()."/".$uri; 
     echo "Redirect triggered to ".$new_url; 

     //header("Location: " . $new_url, TRUE, 302); 
     // exit; 
    } 
} 
0

這個庫是有點老了從未更新過筆者,因爲很長一段時間,它適用於CI 1.7,但這裏是更新版本的CI 2.1兼容。*相同的庫,但工作,你可以從這裏

下載同樣的方式更新版本CodeIgniter 2.1 internationalization i18n

+0

我從github使用新的:)。 – Kyslik

+0

我使用了同樣的一個爲我最近的項目,並沒有任何問題 – umefarooq

+0

我也在不同的項目上使用它! (沒問題)。但是現在出現了這個新問題,在「自動重定向」(從'localhost/my_project/whatever'到'localhost/my_project/en/whatever')之後不會插入尾部斜槓,它實際上會重定向到'localhost/my_project/enw​​hatever'。 – Kyslik