Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用于所有页面的url codeigniter多语言_Php_Mysql_Codeigniter - Fatal编程技术网

Php 用于所有页面的url codeigniter多语言

Php 用于所有页面的url codeigniter多语言,php,mysql,codeigniter,Php,Mysql,Codeigniter,我有多语言网站的基本url localhost/new/。当更改语言时,url localhost/new/en等中会出现语言。问题是当我更改页面时,该语言会禁用localhost/new/popular\u测试,当我停留在该页面时,我更改语言时,url会返回到localhost/new/en。目的是向特定页面添加语言,如localhost/new/popular\u tests/en等 我在控制器中有: public function changeLang($lang_code=''){

我有多语言网站的基本url localhost/new/。当更改语言时,url localhost/new/en等中会出现语言。问题是当我更改页面时,该语言会禁用localhost/new/popular\u测试,当我停留在该页面时,我更改语言时,url会返回到localhost/new/en。目的是向特定页面添加语言,如localhost/new/popular\u tests/en等

我在控制器中有:

public function changeLang($lang_code=''){
            $this->lang->load('main', $lang_code=='' ? 'english' : $lang_code);
                    $this->session->set_userdata('language',$lang_code);

                     redirect(base_url().''.$lang_code);

        }
在config/route.php中,我有:

$route['default_controller'] = 'home';
$route['(:any)/test'] = 'home/test/$1';
$route['popular_tests'] = 'home/popular_tests';
$route['404_override'] = '';
$route['translate_uri_dashes'] = TRUE;


$route['^(\w{2})/(.*)$'] = '$2';
$route['^(\w{2})$'] = $route['default_controller'];

非常感谢。

这是因为您有一个
路由
定义为
$route['^en$']=$route['default\u controller']
这意味着任何以
en
结尾的url都将指向
default\u controller

尝试用以下内容替换该路线:

 $route['^new/(:any)/en$'] = 'home/$1';
 $route['(:any)/new/en$'] = $route['default_controller'];

注:这是未经测试的版本

您应该使用此版本

$route['(\w{2})/test'] = 'home/test';
$route['(\w{2})/(.+)'] = '$2';
$route['(\w{2})'] = $route['default_controller'];

你好,Nishanth Matha,谢谢你的回复。它不起作用。现在,我有了
$route['^(\w{2})/(.*)$']='$2'$路由['^(\w{2})$']=$route['default_controller']
你能给我一些建议吗?我以前的解决方案有什么问题?
$route['^(\w{2})$
中的这个regex
$route['^(\w{2})$']=$route['default\U controller']
将在路由中查找两个单词,如
en
am
,并将指向
default\u controller
,因此任何类似
localhost/en
localhost/am
localhost/zz
的内容都将指向
default\u controller
尝试添加此路由
$route['new/en/(:any)]='1'