Symfony 2.3 FOSUserBundle找不到security.context

时间:2013-08-08 12:45:11

标签: symfony dependency-injection fosuserbundle symfony-2.3

我安装了如下所述的FOS Bundle: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md

使用composer安装并设置用户类后,我总是得到:

[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
 The service "fos_user.security.login_manager" has a dependency on a non-exi
 stent service "security.context".

我检查了路径的存在,并且fosuserbundle中包含了contextinterface ... 使用控制台始终以相同的错误中止。 任何人吗?

我在appKernel中启用了捆绑包(安全捆绑包也被激活了):

        ...
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        ...
        new FOS\UserBundle\FOSUserBundle(),
        ...

我将配置添加到config.yml:

# fos UserBundle config
fos_user:
    db_driver: orm
    firewall_name: main
    user_class: SDDB\MainBundle\Entity\User

我扩展了routing.yml:

# USER AUTH STUFF

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:
    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 }

3 个答案:

答案 0 :(得分:1)

好的,我在FOS Bundle的开发者的帮助下找到了解决方案。

如果你有一个类似的问题,请查看一些基本内容:

  1. FOS Bundle版本是否适合您的Symfony版本?
  2. 是否正确安装了安全捆绑包?
  3. 是否在appkernel中激活了?
  4. 是否有配置文件(security.yml)?
  5. 在(主要)config.yml?
  6. 中是否包含正确的内容

    我在第(4)点的包含行中有一个愚蠢的错字......

答案 1 :(得分:1)

添加:
- {resource:security.yml}到主config.yml的导入部分,它解决了我的问题

答案 2 :(得分:0)

  1. 检查服务文件是否存在(SecurityBundle \ Resources \ config \ security.xml)
  2. 检查服务文件是否已加载(SecurityBundle \ DependencyInjection \ SecurityExtension.php)