【问题标题】:Using multiple languages with routes.php在 routes.php 中使用多种语言
【发布时间】:2012-04-25 23:05:04
【问题描述】:

当我为我的应用程序添加多语言支持时,我的 routes.php 出现问题,某些路由已停止工作。

似乎任何一个片段都有效,任何有两个或更多片段的东西都不起作用。

任何有关如何解决此问题的帮助将不胜感激。

Routes.php 摘录:

// URI like '/en/about' -> use controller 'about'
$route['^(en|br)/(.+)$'] = "$2";
$route['dashboard'] = 'dashboard';    //THIS WORKS
$route['profile'] = 'profile/profile_list';
$route['profile_list/page'] = 'profile/profile_list';    //THIS DOESN'T
$route['profile_list/page/(:any)'] = 'profile/profile_list/$1';
$route['profile/update'] = 'profile/update';
$route['profile/(:any)'] = 'profile/$1';
$route['default_controller'] = 'landing';
// '/en', '/de', '/fr' and '/nl' URIs -> use default controller
$route['^(en|br)$'] = $route['default_controller']; 

【问题讨论】:

  • 所以 /en/profile_list/page 和 /profile_list/page 都不起作用?
  • 是的,它与 url 段的数量有关。我想出了一个解决方案,我将发布。

标签: codeigniter url-rewriting


【解决方案1】:

利用来自Codeigniter forum的信息找出答案

只需要添加这个变量,其中包括我使用的任何两个字母语言代码的 url 段:

$prepended_lang = "(?:[a-zA-Z]{2}/)?"; 

然后相应地修改路线:

$route[$prepended_lang.'logout'] = 'login/logout';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-12
    • 2018-03-16
    • 2019-10-09
    • 1970-01-01
    相关资源
    最近更新 更多