CakePHP 路由,使用带有默认前缀的语言前缀
我正在尝试创建一个默认的路由前缀。
http://localhost/heb/mycont 将转到希伯来语页面,而
http://localhost/mycont 将跳转到英文页面。
Router::connect('/:language/mycont',array('controller'=>'contname','action'=>'index'),array('language'=>'[a-z]{0,3}'));
这段代码允许我使用 0-3 个字母作为语言,但它仍然需要一种语言!
http://localhost/a/mycont 可以使用
http://localhost/mycont 不起作用 有
什么想法如何解决这个问题吗? 甚至可以使用默认路由吗?
I'm trying to create a routing prefix that would be default.
http://localhost/heb/mycont would leave to the Hebrew page, while
http://localhost/mycont would lead to the English page.
Router::connect('/:language/mycont',array('controller'=>'contname','action'=>'index'),array('language'=>'[a-z]{0,3}'));
This code allows me to use 0-3 letters for language, but it still requires a language!
http://localhost/a/mycont would work
http://localhost/mycont doesn't work
Any ideas how to fix that?
Is it even possible with the default routing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我先声明一下,我不是路由专家,但在这种情况下,你所拥有的不起作用是有道理的,因为路由需要语言参数;如果路线不存在,则路线不会匹配。
要“修复”(引用是因为它并没有真正损坏),您可能需要尝试设置默认区域设置,并在
AppController
中覆盖:language
值(如果存在) 。Let me preface this by stating that I'm not a routing expert, but in this case, it makes sense that what you have wouldn't work because the route is expecting a language parameter; the route won't match if it's not there.
To "fix" (quoted since it's not really broken), you might want to try setting your default locale and, in your
AppController
, overwrite if a:language
value is present.我的解决方案只是将 / 设置为特定语言,而其他所有内容都已标记
/:language/
这样我就没有制作重复的路线。
My solution was simply to setup the / to a specific language, while everything else is marked
/:language/
That way I did not make duplicated routes.