0

我想

en/careers to career
fa/careers to career
careers to career

我试过了$route['(en|fa)(.+)/careers'] = 'career';

但它不工作

4

2 回答 2

0

我会在 Routes.php 中使用这个正则表达式

$route['en/careers|fa/careers|careers'] = 'career/index';

图解说明:

在此处输入图像描述

更新:

但我认为将语言字母“en”或“fa”作为参数发送给职业控制器/方法以进行测试......等会更有意义,所以它看起来像这样:

www.example.com/en/careers = www.example.com/careers/lng/en
www.example.com/fa/careers = www.example.com/careers/lng/fa
www.example.com/careers = www.example.com/careers/lng/en 
//(assuming that en is the default language if no language was specified)

如果这是有道理的,那么你应该像这样遵循这 3 条规则

$route['(en)/careers'] = 'career/lng/$1';
$route['(fa)/careers'] = 'career/lng/$1';
$route['careers'] = 'career/lng/en';

这是在 careers.php 中的 lng() 方法

 public function lng($lang_id)
 {
    if($lang_id == "en")  
        echo "welcome"; 
    elseif($lang_id == "fa")
        echo "خوش آمد";  // not sure if this is correct in "fa" language :p
 }

注意:如果您的语言在数据库中存储了 id ...等,您可以将 $1 更改为数字 id

$route['en/careers'] = 'career/lng/1';
$route['fa/careers'] = 'career/lng/2';
$route['careers'] = 'career/lng/1';

那么您的 lng() 方法将如下所示

 public function lng($lang_id)
 {
    if($lang_id == 1)  
        echo "welcome"; 
    elseif($lang_id == 2)
        echo "خوش آمد";  // not sure if this is correct in "fa" language :p
 }

我希望这会有所帮助

于 2015-08-30T19:16:13.707 回答
0

制作en/fa/可选:

(en/|fa/)?careers
于 2015-08-30T09:20:05.890 回答