覆盖FOSUserBundle路由Symfony2 [英] Override FOSUserBundle routes Symfony2
问题描述
我想覆盖来自FOSUserBundle的某些路由
I would like to override some routes from FOSUserBundle
MyBundle/Resources/config/routing/security.yml
fos_user_security_login:
path: /{_locale}/login
defaults: { _controller: FOSUserBundle:Security:login }
requirements:
_locale: %locales%
fos_user_security_check:
path: /login_check
defaults: { _controller: FOSUserBundle:Security:check }
requirements:
_locale: %locales%
fos_user_security_logout:
path: /{_locale}/logout
defaults: { _controller: FOSUserBundle:Security:logout }
requirements:
_locale: %locales%
但是它不起作用,找不到路由
But it does not works, route are not found
MyBundle/Resources/config/routing/security.xml
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="fos_user_security_login" pattern="/{_locale}/login">
<default key="_controller">FOSUserBundle:Security:login</default>
</route>
<route id="fos_user_security_check" pattern="/login_check">
<default key="_controller">FOSUserBundle:Security:check</default>
<requirement key="_method">POST</requirement>
</route>
<route id="fos_user_security_logout" pattern="/{_locale}/logout">
<default key="_controller">FOSUserBundle:Security:logout</default>
</route>
</routes>
这有效,但我不知道如何从parameter.yml中传递我的语言环境参数
This works but I don't know how to pass my locales parameter from parameter.yml
推荐答案
首先,yaml路由不起作用,因为FOSUserBundle路由是在xml中定义的. 因此,您的Yaml路线不会导入.
First of all the the yaml routes are not working because the FOSUserBundle Routes are defined in xml. So your yaml routes won't imported.
此处FOSUserBundle路由: https://github.com/FriendsOfSymfony/FOSUserBundle/tree/master/Resources/config/routing
here the FOSUserBundle Routes: https://github.com/FriendsOfSymfony/FOSUserBundle/tree/master/Resources/config/routing
如果FOSUserBundle是userbundle的父捆绑,则可以重写FOSUserBundle路由资源. 此处说明了如何执行此操作: http://symfony.com/doc/current/cookbook/bundles/inheritance.html#overriding-resources-templates-routing-etc
If the FOSUserBundle is the parent bundle of your userbundle you are able to rewrite the FOSUserBundle routing resources. How to do this is explained here: http://symfony.com/doc/current/cookbook/bundles/inheritance.html#overriding-resources-templates-routing-etc
这里还介绍了如何将语言环境传递到路线的最后一点: http://symfony.com/doc/current/cookbook/bundles/inheritance.html#overriding-resources-templates-routing-etc
Further more to answer to the last point how to pass the locale into the route is described here: http://symfony.com/doc/current/cookbook/bundles/inheritance.html#overriding-resources-templates-routing-etc
<route id="contact" path="/{_locale}/contact">
<default key="_controller">AcmeDemoBundle:Contact:index</default>
<requirement key="_locale">%locales%</requirement>
</route>
这篇关于覆盖FOSUserBundle路由Symfony2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!