导航不使用路径变量值

时间:2016-12-12 02:49:15

标签: php zend-framework zend-framework2 zend-navigation

我在这里指定了一种语言:lang(Zend Framework 3):

'contact' => [
    'type' => Segment::class,
    'options' => [
                'route' => '/:lang/hello',
                'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action' => 'contact',
                            'lang'       => 'en'
                ]
    ],
],

当我转到网页http://localhost/pp/public/it/hello时,它会将it值存储到lang segment

问题在于我的导航它显示的其他区域如下所示:

http://localhost/pp/public/en/services

应该是

http://localhost/pp/public/it/services

Zend\Navigation是否没有使用值it而不是默认值en作为路径程序集的lang参数 < / p>

1 个答案:

答案 0 :(得分:0)

根据Sven Buis评论,您可以手动将当前值添加到每个url帮助程序调用,但这可能不是最好的方法,因为这意味着为了一个目的几乎无处不在地添加代码。

另一种解决方案是简单地使用url视图助手的最后一个参数,该参数允许重用当前路由参数(将其设置为true,默认为false)。我也不喜欢这个解决方案,因为你可以有一些边缘情况,其中所有的默认值都没有被重新定义,这可能会破坏你不想要的地方的代码。

您可以查看https://github.com/juriansluiman/SlmLocale中使用的方法(到目前为止仅适用于ZF2,我没有时间完成ZF3的PR)。它使用事件系统连接调度循环并在那里的某处设置语言设置。

相关问题