在分析了CI的代碼和博客中的代碼之後,我已經提出了這個解決方案。
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class About extends CI_Controller {
function index()
{
// you might want to just autoload these two helpers
$this->load->helper('language');
$this->load->helper('url');
$this->getLang();
$this->load->view('about');
}
function getLang(){
$url = $_SERVER['REQUEST_URI'];
$lang = explode("/", $url);
if($lang[2] == 'en'){
// load language file
return $loadLang = $this->lang->load('english','english');
}
else if($lang[2] == 'fr'){
// load language file
return $loadLang = $this->lang->load('french','french');
}
else{
// load language file
return $loadLang = $this->lang->load('english','english');
}
return false;
}
}
我創建了功能getLang()中,我加載語言文件。
$this->lang->load('language_file','language_folder');