Routing Zend Framework 2 Language in url

空扰寡人 提交于 2019-12-04 08:53:23

I think your regex needs to be

'regex'    => '/(?<lang>(de|fr|nl)?)'

You could so the same with a Segment route and an appropriate constraint...

'router' => array(
    'routes' => array(
        'home' => array(
            'type' => 'Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'language' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route' => '[/:lang]',
                        'defaults' => array(
                            'lang' => 'en', //default
                        ),
                        'constraints' => array(
                            'lang' => '(en|de|fr|nl)?',
                        ),
                    ),
                ),
            ),
        ),
    ),
),
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!