1

我安装了 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 }
4

3 回答 3

2

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

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

  1. FOS Bundle 版本是否适合您的 Symfony 版本?
  2. 是否正确安装了安全包?
  3. 它是在应用内核中激活的吗?
  4. 是否有它的配置文件(security.yml)?
  5. 它是否正确包含在(main)config.yml 中?

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

于 2013-08-09T09:30:06.310 回答
1

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

于 2015-03-24T15:16:16.073 回答
0
  1. 检查服务文件是否存在(SecurityBundle\Resources\config\security.xml)
  2. 检查服务文件是否加载(SecurityBundle\DependencyInjection\SecurityExtension.php)
于 2013-08-08T14:15:56.427 回答