cakephp 通过 url 选择语言
我想要实现的目标在这里描述 http://nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for -i18n-and-l10n-国际化和本地化/ 但我无法让它工作。
路由器配置如下所示:
Router::connect('/registered/:language/:controller/:action/*',
array('prefix' => 'registered', 'registered' => true, 'layout'=> 'registered'),
array('language' => '[a-z]{3}'));
但是当我尝试访问 www.example.com/registered/cze/packages
时,我得到:
错误:无法找到 CzeController。
作为作者,我使用 cake 1.3,而不是 1.2,这可能是问题所在,但是我需要更改什么才能使其正常工作?
编辑:
$this->Session->write('Config.language','cze');
此代码有效,并且在控制器中使用时会更改站点的语言,但我需要根据 URL 让它工作
what I am trying to achieve is described here http://nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for-i18n-and-l10n-internationalization-and-localization/
but I can not get it working.
The router configurations looks like this:
Router::connect('/registered/:language/:controller/:action/*',
array('prefix' => 'registered', 'registered' => true, 'layout'=> 'registered'),
array('language' => '[a-z]{3}'));
butw when I try to go to www.example.com/registered/cze/packages
I get:
Error: CzeController could not be found.
I am using cake 1.3, not 1.2 as the author, that may be the problem, but what do I need to change in order for this to work?
Edit:
$this->Session->write('Config.language','cze');
This code works and when used in the controller changes the language of the site, but I need to get it working according to the URL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
URL
www.example.com/registered/cze/packages
与路由/registered/:language/:controller/:action/*
不匹配,因为>:action
段为空。因此,URL 会进入标准路由,其中registered
被识别为前缀,cze
被识别为控制器。您还需要创建一个“更短”的
/registered/:language/:controller
路由来捕获“缩写”URL。The URL
www.example.com/registered/cze/packages
does not match the route/registered/:language/:controller/:action/*
, since the:action
segment is empty. Therefore, the URL falls through to the standard route, whereregistered
is recognized as the prefix andcze
as the controller.You'll need to create a "shorter"
/registered/:language/:controller
route as well to catch "abbreviated" URLs.