有没有办法设置基于主机名的路由Symfony2?
我在官方文档中没有找到有关此主题的任何内容。
http://symfony.com/doc/2.0/book/routing.html http://symfony.com/doc/2.0/book/routing.html
我想根据给定的主机名路由请求:
foo.example.com
bar.example.com
{{子域名}}.example.com
因此本质上,控制器将获取当前子域作为参数传递。
与Zend的解决方案类似:
http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.hostname http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.hostname
$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
':username.users.example.com',
array(
'controller' => 'profile',
'action' => 'userinfo'
)
);
$plainPathRoute = new Zend_Controller_Router_Route_Static('');
$router->addRoute('user', $hostnameRoute->chain($plainPathRoute));
我希望这是可能的,但我只是以某种方式错过了它。
提前致谢!
只是要指出,它现在已添加到 Symfony v2.2 中 -http://symfony.com/doc/master/components/routing/hostname_pattern.html http://symfony.com/doc/master/components/routing/hostname_pattern.html.
mobile_homepage:
path: /
host: m.{domain}
defaults: { _controller: AcmeDemoBundle:Main:mobileHomepage }
requirements:
domain: %domain%
homepage:
path: /
defaults: { _controller: AcmeDemoBundle:Main:homepage }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)