Symfony2/FOSUserBundle - 路由多个包的问题 [英] Symfony2/FOSUserBundle - Route issues with multiple bundles

查看:51
本文介绍了Symfony2/FOSUserBundle - 路由多个包的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Similar to this problem, I need a separate login for both the admin and front end bundles of my site. The admin is actually a separate bundle located in vendors.

现在,我的路由看起来像:

Right now, my routing looks like:

app/config/routing.yml:

app/config/routing.yml:

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

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

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

Both of the bundles' individual routing.yml files have:

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 中的防火墙:

And my firewalls in 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,这不是我想要发生的.

The problem is that the front end's automatically generated login links point to /admin/login rather than just /login, which is not what I want to have happen.

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

So, how can I make it use the /admin/* links when I'm there, but just the / links when I'm on the front end? I need to keep their contexts linked as people logged into the admin side should stay logged in on the front end.

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

I renamed my routes as the following:

SiteBundle 的 routing.yml(和之前一样):

SiteBundle's routing.yml (same as before):

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:

AdminBundle's 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 中.

As you can see, the only route that is correct is for user registration, and that's only because it's located just in SiteBundle's routing.yml.

推荐答案

想通了:

由于 FOSUserBundle 已在 config.yml 中向我的管理防火墙注册,因此即使在我重命名它们之后,它仍然默认为其路由.因此,将它们转回 fos_*,并重命名 site 捆绑包的路由似乎已修复它.

Since the FOSUserBundle was registered with my admin firewall in config.yml, it kept defaulting to its routes even after I renamed them. So, turning them back to fos_*, and renaming the site bundle's routes seems to have fixed it.

这篇关于Symfony2/FOSUserBundle - 路由多个包的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆