Routing ZF2语言的子域路由
对于我的应用程序,我想利用子域设置语言,例如: -site.com(英文) -de.site.com(德语) -nl.site.com(荷兰语) 我将子域配置设置为:Routing ZF2语言的子域路由,routing,zend-framework2,subdomain,Routing,Zend Framework2,Subdomain,对于我的应用程序,我想利用子域设置语言,例如: -site.com(英文) -de.site.com(德语) -nl.site.com(荷兰语) 我将子域配置设置为: 'home' => array( 'type' => 'hostname', 'options' => array( 'route' => ':lang.site.:tld', 'defau
'home' => array(
'type' => 'hostname',
'options' => array(
'route' => ':lang.site.:tld',
'defaults' => array(
'controller' => 'Application\Controller\Application',
'action' => 'index',
'lang' => 'en',
),
'constraints' => array(
'lang' => '(|nl|de)',
'tld' => '(localhost|com)',
),
),
我面临的问题是,我只想浏览英文版(site.com)
没有子域,但我遇到了“找不到页面”,我想我….'route'=>':lang.site.:tld'。。作为“[:lang]。站点:tld”,但这似乎不起作用
有人吗?:)
提前感谢,
尼克我打赌你在
:lang
参数后有一个点,这不允许像site.com
这样的url通过(.site.com
可能)。因此,我将:lang
设置为可选——当为空时,它应该返回到默认值en
值。
我也没有看到:tld
param存在的任何原因,所以我把它扔掉了。我猜您一开始并不需要它,因为您提供了url示例
'home' => array(
'type' => 'hostname',
'options' => array(
'route' => '[:lang][.]site.com',
'defaults' => array(
'controller' => 'Application\Controller\Application',
'action' => 'index',
'lang' => 'en',
),
'constraints' => array(
'lang' => '(en|nl|de)',
),
),
为了完整性起见,我还向您的备选方案中加入了en
,这不会影响匹配,因为只有在存在参数值时才应该检查约束
我没有时间测试它,但我认为如果我对ZF2路由的理解是正确的,那么它应该可以工作。您可以查看SlmLocale及其主机策略()。不在路由中执行i18n有几个优点,SlmLocale解决了这一问题。当您选择了默认的语言环境时,它没有在主机策略中跳过语言环境部分的选项。。。