gpt4 book ai didi

php - Symfony2/FOSUserBundle - 多个包的路由问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:38:58 24 4
gpt4 key购买 nike

类似于this问题,我需要为我网站的管理员和前端包单独登录。 admin 实际上是位于 vendors 中的一个单独的包。

现在,我的路线如下:

应用程序/配置/routing.yml:

AcmeSiteBundle:
resource: "@SiteBundle/Resources/config/routing.yml"
prefix: /

AcmeAdminBundle:
resource: "@AdminBundle/Resources/config/routing.yml"
prefix: /admin/

两个包的单独 routing.yml 文件都有:

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

fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile

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

fos_user_security_login:
pattern: /login
defaults: { _controller: FOSUserBundle:Security:login }

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

fos_user_security_logout:
pattern: /logout
defaults: { _controller: FOSUserBundle:Security:logout }

还有我在 security.yml 中的防火墙:

firewalls:
main:
context: site
pattern: ^/admin/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
login_path: /admin/login
check_path: /admin/login_check
logout:
path: /admin/logout
anonymous: true

frontend:
context: site
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
login_path: /login
check_path: /login_check
logout:
path: /logout
anonymous: true

问题是前端自动生成的登录链接指向/admin/login 而不仅仅是/login,这不是我想要发生的。

那么,我怎样才能让它在我在那里时使用 /admin/* 链接,而在我在前端时只使用 / 链接?我需要保持他们的上下文链接,因为登录到管理端的人应该在前端保持登录状态。


编辑:我将我的路线重命名如下:

SiteBundle 的 routing.yml(同前):

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

fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile

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

fos_user_security_login:
pattern: /login
defaults: { _controller: FOSUserBundle:Security:login }

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

fos_user_security_logout:
pattern: /logout
defaults: { _controller: FOSUserBundle:Security:logout }

AdminBundle 的 routing.yml:

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

_admin_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile

_admin_user_security_login:
pattern: /login
defaults: { _controller: FOSUserBundle:Security:login }

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

_admin_user_security_logout:
pattern: /logout
defaults: { _controller: FOSUserBundle:Security:logout }

$ app/console router:debug 显示:

fos_user_registration_register         ANY    ANY    ANY  /register/
fos_user_registration_check_email GET ANY ANY /register/check-email
fos_user_registration_confirm GET ANY ANY /register/confirm/{token}
fos_user_registration_confirmed GET ANY ANY /register/confirmed
fos_user_security_login ANY ANY ANY /admin/login
fos_user_security_check ANY ANY ANY /admin/login_check
fos_user_security_logout ANY ANY ANY /admin/logout
fos_user_profile_show GET ANY ANY /admin/profile/
fos_user_profile_edit ANY ANY ANY /admin/profile/edit
_admin_user_security_login ANY ANY ANY /admin/login
_admin_user_security_check ANY ANY ANY /admin/login_check
_admin_user_security_logout ANY ANY ANY /admin/logout

如您所见,唯一正确的路由是用户注册,那只是因为它刚好位于 SiteBundle 的 routing.yml 中。

最佳答案

想通了:

由于 FOSUserBundle 已在 config.yml 中注册到我的管理防火墙,即使在我重命名它们之后,它仍然默认使用它的路由。因此,将它们转回 fos_*,并重命名 site 包的路由似乎已经解决了这个问题。

关于php - Symfony2/FOSUserBundle - 多个包的路由问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16279378/

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