Symfony2 / FOSUserBundle - 使用多个捆绑包路由问题

时间:2013-04-29 13:04:33

标签: php symfony user-management

this问题类似,我需要为我的网站的管理员和前端捆绑包单独登录。管理员实际上是位于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中

1 个答案:

答案 0 :(得分:4)

想出来:

由于FOSU​​serBundle已在config.yml中注册了我的管理防火墙,因此即使我重命名它们,它仍然默认为其路由。所以,将它们转回fos_ *,并重命名 site 包的路线似乎已修复它。