Php Zend Framework 2:主机名和重定向
我需要在zend framework 2项目中创建一个路由,帮助我创建以下url:Php Zend Framework 2:主机名和重定向,php,zend-framework,zend-framework2,zend-route,Php,Zend Framework,Zend Framework2,Zend Route,我需要在zend framework 2项目中创建一个路由,帮助我创建以下url: 和.net 和.net 代码: <?php return array ( 'router' => array ( 'routes' => array ( 'username' => array ( 'type' => 'hostname',
- 和.net
- 和.net
<?php
return array (
'router' => array (
'routes' => array (
'username' => array (
'type' => 'hostname',
'options' => array (
'route' => ':username.test.:tld',
'constraints' => array(
'username' => '[a-zA-Z][a-zA-Z0-9_-]*',
'tld' => '[com|net]*',
),
'defaults' => array (
'controller' => 'Application\Controller\Index',
'action' => 'show',
'tld' => 'com'
)
)
),
'home' => array (
'type' => 'hostname',
'options' => array (
'route' => 'www.test.:tld',
'constraints' => array(
'tld' => '[com|net]*',
),
'defaults' => array (
'controller' => 'Application\Controller\Index',
'action' => 'index',
'tld' => 'com'
)
)
),
)
),
这里的“问题”是您想要将ZfcUser路由设置为您的主路由的子路由。但是,ZfcUser只将路由设置为根路由,而不是您的子路由
解决方案是使用“原型”和chain\u routes
键。这是相当没有文件,但你可以阅读一些信息
基本上,将顶级路由(“home”和“username”)转换为原型,并为ZfcUser路由设置chain_routes
键
<a href="<?php echo $this->url('zfcuser') ?>" title="Profilo"><i class="fa fa-user"></i><?php echo $this->translate('Your Profile') ?></a>