dir*_*ory 5 parameters url translation routes zend-framework2
对于我的应用程序翻译,我想使用一种语言结构,例如:
等等..
我可以使用Literal中的路由器选项轻松地完成此操作,因为'[az] {2}'但我想排除我不支持的语言,例如site.com/it/如果不支持我想要404.我试过使用正则表达式(添加支持的语言)修复此问题但是(我不知道)出错了.
提前致谢!
'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' => 'Regex',
'options' => array(
'regex' => '/(?<lang>(de|fr|nl))?',
'defaults' => array(
'lang' => 'en', //default
),
'spec' => '/%lang%',
),
),
),
),
),
),
Run Code Online (Sandbox Code Playgroud)
我认为你的正则表达式需要
'regex' => '/(?<lang>(de|fr|nl)?)'
Run Code Online (Sandbox Code Playgroud)
您可以使用Segment路径和适当的约束来实现相同的...
'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)?',
),
),
),
),
),
),
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3057 次 |
| 最近记录: |