【问题标题】:How to include language segment in the URL for links in Cake 3.0如何在 Cake 3.0 中的链接的 URL 中包含语言段
【发布时间】:2015-10-08 19:10:01
【问题描述】:

我需要建立一个多语言网站,网址中的语言像这样http://example.org/jp/users/login,但我想避免将语言编码到网站上的每个链接中。我实际上有这个路由:

$routes->connect(
    '/:lang/:controller/:action/*',
    ['prefix' => 'customer'],
    ['routeClass' => 'DashedRoute', 'lang' => '[a-z]{2}']
);

我必须为链接这样做:

$this->Html->link(__('List Users'), ['lang' => 'en', 'controller' => 'users', 'action' => 'index']);

有什么方法可以自动添加 lang 而我可以只为链接执行此操作?

$this->Html->link(__('List Users'), ['controller' => 'users', 'action' => 'index']);

【问题讨论】:

    标签: cakephp routing routes cakephp-3.0


    【解决方案1】:

    只需将'persist' => ['lang'] 添加到$routes->connect() 语句的选项数组即可。

    【讨论】:

    • 您可以尝试使用我的i18n 插件,它提供了自定义路由类来简化使用语言前缀/片段的连接路由。
    猜你喜欢
    • 2015-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-24
    • 1970-01-01
    • 1970-01-01
    • 2021-03-21
    • 2011-09-23
    相关资源
    最近更新 更多