FOSUserBundle路由未解析 - 重定向到默认控制器

时间:2013-07-18 11:43:08

标签: symfony fosuserbundle

每当我尝试访问mypage/register或FOSUserBudnle创建的任何其他页面时,我都会被重定向到我的默认控制器mypage/,而不是注册页面。

这些是我的路由文件:

(app\config\routing.yml)

my_website:
resource: "@MyWebsiteBundle/Resources/config/routing.yml"
prefix:   /

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_resetting:
    resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
    prefix: /resetting

fos_user_change_password:
    resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
    prefix: /{_locale}/profile

另一个(Resources \ config \ routing.yml)

mywebsite_first:
    pattern:  /{_locale}/
    defaults: { _controller: MyWebsiteBundle:Default:index }

mywebsite_calendar:
    pattern: /{_locale}/calendar
    defaults: { _controller: MyWebsiteBundle:Calendar:index }

mywebsite_home:
    pattern: /{_locale}/home
    defaults: { _controller: MyWebsiteBundle:Home:index }

mywebsite_messages:
    pattern: /{_locale}/messages
    defaults: { _controller: MyWebsiteBundle:Messages:index }

另外 - 我的security.yml文件

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
            logout:       true
            anonymous:    true

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }

我做错了什么?

1 个答案:

答案 0 :(得分:0)

它不起作用,因为它与您网站路由的_locale参数匹配,Symfony路由器将始终选择它找到的第一个匹配路由。

您需要添加路线要求:

mywebsite_first:
    pattern:  /{_locale}/
    defaults: { _controller: MyWebsiteBundle:Default:index }
    requirements:
    _locale: en|fr|de

或者只是在FOSUser的路线之后放置网站的路线。