5

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

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

应用程序/配置/路由.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 中。

4

1 回答 1

4

弄清楚了:

由于 FOSUserBundle 是在 config.yml 中向我的管理防火墙注册的,因此即使在我重命名它们之后,它仍然默认使用它的路由。因此,将它们转回 fos_*,并重命名站点包的路由似乎已经修复了它。

于 2013-04-29T17:29:06.210 回答