我想覆盖一些来自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%
但它不起作用,找不到路线
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传递我的locales参数
答案 0 :(得分:8)
首先,yaml路由不起作用,因为FOSUserBundle路由是在xml中定义的。 所以你的yaml路线不会被导入。
这里是FOSUserBundle路线: 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
此处还介绍了如何回答最后一点如何将语言环境传递到路由中: 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>