gpt4 book ai didi

php - 如何自定义 FOS UserBundle URL

转载 作者:IT王子 更新时间:2023-10-29 01:05:25 31 4
gpt4 key购买 nike

我已经安装了 FOSUserBundle我想将 url 自定义为 /account/login/account/register/account/logout 而不是 /登录, /register, /logout

我知道我可以修改 bundle 的路由配置,但它似乎不是正确的方法。

最佳答案

如何覆盖/更改 FOSUserBundle 的路由

您可以在app/config/routing.yml 中覆盖/register 路由,方法是之后重新声明 将 FOSUserBundle 的 XML 路由作为资源导入。

fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register

# ...

fos_user_registration_register:
path: /account/register
defaults: { _controller: FOSUserBundle:Registration:register }

...或在导入时更改前缀:

fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /account/register

# no need to override the route

同样适用于 /login/logout :

fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"

# ...

fos_user_security_login:
path: /account/login
defaults: { _controller: FOSUserBundle:Security:login, _method: POST }

fos_user_security_logout:
path: /account/login
defaults: { _controller: FOSUserBundle:Security:logout, _method: POST }

另一种覆盖登录和注销 url 的方法

登录和注销路径也可以直接在您的 app/config/security.yml 中配置:

security:
firewalls:
your_firewall:
# ...
form_login:
login_path: /account/login # instead of fos_user_security_login
# ...
logout:
path: /account/logout # instead of fos_user_security_logout
# ...

YAML 格式的所有 FOSUserBundle 路由列表

您可以直接更改然后将它们包含在您的 app/config/routing.yml 中(不需要导入包提供的资源)...或者将它们全部放入单个文件并将该文件作为资源包含...

# -> from @FOSUserBundle/Resources/routing/change_password.xml

fos_user_change_password:
pattern: /profile/password/change
defaults: { _controller: FOSUserBundle:ChangePassword:changePassword }
requirements:
_method: GET|POST

# -> from @FOSUserBundle/Resources/routing/group.xml

fos_user_group_list:
pattern: /groups/list
defaults: { _controller: FOSUserBundle:Group:list }
requirements:
_method: GET

fos_user_group_new:
pattern: /groups/new
pattern:
defaults: { _controller: FOSUserBundle:Group:new }
requirements:
_method: GET

fos_user_group_show:
pattern: /groups/{groupname}
defaults: { _controller: FOSUserBundle:Group:show }
requirements:
_method: GET

fos_user_group_edit:
pattern: /groups/{groupname}/edit
defaults: { _controller: FOSUserBundle:Group:edit }
requirements:
_method: GET|POST

fos_user_group_delete:
pattern: /groups/{groupname}/delete
defaults: { _controller: FOSUserBundle:Group:delete }
requirements:
_method: GET

# -> from @FOSUserBundle/Resources/routing/profile.xml

fos_user_profile_show:
pattern: /profile/show
defaults: { _controller: FOSUserBundle:Profile:show }
requirements:
_method: GET

fos_user_profile_edit:
pattern: /profile/edit
defaults: { _controller: FOSUserBundle:Profile:edit }
requirements:
_method: GET|POST

# -> from @FOSUserBundle/Resources/routing/registration.xml

fos_user_registration_register:
pattern: /registration
defaults: { _controller: FOSUserBundle:Registration:register }
requirements:
_method: GET|POST

fos_user_registration_check_email:
pattern: /registration/check-email
defaults: { _controller: FOSUserBundle:Registration:checkEmail }
requirements:
_method: GET

fos_user_registration_confirm:
pattern: /registration/confirm/{token}
defaults: { _controller: FOSUserBundle:Registration:confirm }
requirements:
_method: GET

fos_user_registration_confirmed:
pattern: /registration/confirmed
defaults: { _controller: FOSUserBundle:Registration:confirmed }
requirements:
_method: GET

# -> from @FOSUserBundle/Resources/routing/resetting.xml

fos_user_resetting_request:
pattern: /profile/password/reset
defaults: { _controller: FOSUserBundle:Resetting:request }
requirements:
_method: GET

fos_user_resetting_send_email:
pattern: /profile/password/reset
defaults: { _controller: FOSUserBundle:Resetting:sendEmail }
requirements:
_method: POST

fos_user_resetting_check_email:
pattern: /profile/password/reset/check-email
defaults: { _controller: FOSUserBundle:Registration:checkEmail }
requirements:
_method: GET

fos_user_resetting_reset:
pattern: /profile/password/reset/{token}
defaults: { _controller: FOSUserBundle:Registration:reset }
requirements:
_method: GET|POST

# -> from @FOSUserBundle/Resources/routing/security.xml

fos_user_security_login:
pattern: /login
defaults: { _controller: FOSUserBundle:Security:login }
requirements:
_method: GET|POST

fos_user_security_check:
pattern: /login_check
defaults: { _controller: FOSUserBundle:Security:check }

fos_user_security_logout:
pattern: /logout
defaults: { _controller: FOSUserBundle:Security:logout }
requirements:
_method: GET|POST

关于php - 如何自定义 FOS UserBundle URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19608458/

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