gpt4 book ai didi

symfony - 覆盖 FOSUserBundle 路由 Symfony2

转载 作者:行者123 更新时间:2023-12-04 05:38:54 25 4
gpt4 key购买 nike

我想覆盖来自 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 传递我的语言环境参数

最佳答案

首先,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>

关于symfony - 覆盖 FOSUserBundle 路由 Symfony2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25444390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com