覆盖FOSUserBundle路由Symfony2[英] Override FOSUserBundle routes Symfony2

本文是小编为大家收集整理的关于覆盖FOSUserBundle路由Symfony2的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我想覆盖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

传递我的erentes参数

推荐答案

首先,YAML路由不起作用,因为FosuserBundle路由是在XML中定义的. 因此您的YAML路线不会导入.

在这里,FosuserBundle路线: https://github.com/github.com/firdsofsymfony/firdsofsymfony/fosusemfony/fosususerbundle/fosuserbundle/tree/tree/tree/master/master/reserces/resources/config/config/config/routing一下<一下/a>

如果fosuserbundle是您的用户行的父束,则可以重写fosuserbundle路由资源. 在这里解释了如何做到这一点: 捆绑/sashitance.html#覆盖 - 归因 - templates-routing-etc

更多地回答了最后一点如何将其传递到路线的最后一点:此处描述: 捆绑/sashitance.html#覆盖 - 归因 - templates-routing-etc

<route id="contact" path="/{_locale}/contact">
    <default key="_controller">AcmeDemoBundle:Contact:index</default>
    <requirement key="_locale">%locales%</requirement>
</route>

本文地址:https://www.itbaoku.cn/post/2090767.html

问题描述

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>

This works but I don't know how to pass my locales parameter from parameter.yml

推荐答案

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.

here the FOSUserBundle Routes: https://github.com/FriendsOfSymfony/FOSUserBundle/tree/master/Resources/config/routing

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

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>