编程语言
首页 > 编程语言> > php-为语言路径设置codeigniter路由

php-为语言路径设置codeigniter路由

作者:互联网

所以我使用的是Codeigniter 2.1 Internationalization i18n Library,我需要调整路由以在删除了控制器名称的短网址中使用语言参数:

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

#$route['^(en|es|ro)/(.+)$'] = "$2";
#$route['^(en|es|ro)$'] = $route['default_controller'];

$route['results$']      = "fetch/results";
$route['video/(:any)']  = "fetch/video/$1";
$route['tag/(:any)']    = "fetch/tag/$1";

$route['404_override'] = '';

所以我需要使这项工作http:// localhost / app / en / results?query = t-shirts而不是http:// localhost / app / en / fetch / results?query = t-shirts

我该怎么做?

编辑:

$route['^(en|es|ro)/results$'] = "fetch/results";
$route['^(en|es|ro)/video/(:any)'] = "fetch/video/$1";
$route['^(en|es|ro)/video/(.+)$'] = $route['^(en|es|ro)/(.+)$'] = "$2";"fetch/video/$2";

以上都不是.

如果我这样做http:// localhost / app / en / fetch / video / asfasf可以正常工作

这不是http:// localhost / app / en / video / asfasf

我得到的错误是404:

404 Page Not Found

The page you requested was not found.

发现问题

因此,出于某种原因设置了此地址:$route [‘^(en | es | ro)/(.)$’] =“ $2”;在我试图造成问题之前.

解决方法:

对于使用该库并想要设置自定义路由的任何人,要使其正常工作,您必须按以下顺序进行:

>自定义路线
>图书馆添加的路线

例:

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

//First
$route['^(en|es|ro)/video/(.+)$'] = "fetch/video/$2";
$route['^(en|es|ro)/results$']     = "fetch/results$2";
//Second
$route['^(en|es|ro)/(.+)$']        = "$2";
$route['^(en|es|ro)$'] = $route['default_controller'];


$route['404_override']  = '';

标签:codeigniter,codeigniter-routing,php,regex,internationalization
来源: https://codeday.me/bug/20191201/2084400.html