cakephp choosing language by url

吃可爱长大的小学妹 提交于 2019-12-24 17:18:21

问题


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


回答1:


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, where registered is recognized as the prefix and cze as the controller.

You'll need to create a "shorter" /registered/:language/:controller route as well to catch "abbreviated" URLs.



来源:https://stackoverflow.com/questions/4550670/cakephp-choosing-language-by-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!