Symfony2:路由器没有使用正确的控制器

时间:2015-04-03 22:03:12

标签: php symfony fosuserbundle

我是Symfony2的新手,我尝试使用FOSUserBundle。 但是/ login url没有使用正确的控制器,而是之前使用的旧控制器:

  

“OC \ UserBundle \控制器\ SecurityController ::则loginAction”

Symfony profiler路由工具告诉我找到了/ login模式的道路“fos_user_security_login”:

fos_user_security_login        /login         Route matches!

但是,探查器主页也告诉我:

Request Attributes

Key Value
_controller "OC\\UserBundle\\Controller\\SecurityController::loginAction"
_route      "fos_user_security_login"

我检查了10次以上但是在路由和安全文件等任何文件中找不到任何对旧控制器的引用,除了在缓存中(使用phpStorm高级搜索功能)。 当然,我使用以下命令清除了缓存:

  

app / console cache:clear

你知道这可能来自哪里吗?

以下是我的路由和安全文件:

供应商/ friendsofsymfony /用户束/ Ressources /配置/路由/ security.xml文件

(这里我们可以看到这是FOSUserBundle:安全:应该使用的登录控制器)

<routes xmlns="http://symfony.com/schema/routing"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

    <route id="fos_user_security_login" pattern="/login">
        <default key="_controller">FOSUserBundle:Security:login</default>
    </route>

    <route id="fos_user_security_check" pattern="/login_check">
        <default key="_controller">FOSUserBundle:Security:check</default>
        <requirement key="_method">POST</requirement>
    </route>

    <route id="fos_user_security_logout" pattern="/logout">
        <default key="_controller">FOSUserBundle:Security:logout</default>
    </route>

</routes>

应用/配置/ routing.yml中

oc_platform:
    resource: "@OCPlatformBundle/Resources/config/routing.yml"
    prefix:   /

app:
    resource: "@AppBundle/Controller/"
    type:     annotation



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: /profile

应用/配置/ security.yml

security:
    encoders:
        OC\UserBundle\Entity\User: sha512

    role_hierarchy:
        ROLE_ADMIN:       [ROLE_TESTEUR, ROLE_MODERATEUR]
        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        main:
            id: fos_user.user_provider.username


    firewalls:
        main_login:
            pattern: ^/login$
            anonymous: true

        main:
            pattern: ^/
            anonymous: true
            provider: main
            form_login:
                login_path: fos_user_security_login
                check_path: fos_user_security_check
            logout:
                path: fos_user_security_logout
                target: /
            remember_me:
                key: %secret%


        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false

        login:
            security: false

        secured_areas:
            anonymous: ~




    access_control:
        - { path: ^/demo/secured/hello/admin/, roles: ROLE_ADMIN }
        #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }

的src / OC / PlatformBundle / Ressources /配置/ routing.yml中

oc_platform_homepage:
    path:     /hello/{name}
    defaults: { _controller: OCUserBundle:Default:index }


oc_affiche:
    path:     /hello-world
    defaults: { _controller: OCPlatformBundle:Default:affiche }


oc_home:
    path: /
    defaults: { _controller: OCPlatformBundle:Test:home }

oc_form_show:
    path: /addTest
    defaults: { _controller: OCPlatformBundle:Test:add }

oc_platform_test_view:
    path: /viewTest/{id}
    defaults: { _controller: OCPlatformBundle:Test:view }

oc_platform_test_viewAll:
    path: /viewTest
    defaults: { _controller: OCPlatformBundle:Test:viewAll }


oc_platform_test_user:
    path: /viewUser
    defaults: { _controller: OCPlatformBundle:Test:viewUser }

oc_platform_test_admin:
    path: /viewAdmin
    defaults: { _controller: OCPlatformBundle:Test:viewAdmin }

1 个答案:

答案 0 :(得分:0)

猜测,您的路线映射在@OCPlatformBundle/Resources/config/routing.yml