【问题标题】:Troubles installing FOSUserBundle in Symfony 3.0.4在 Symfony 3.0.4 中安装 FOSUserBundle 时遇到问题
【发布时间】:2016-04-14 17:44:12
【问题描述】:

在 Symfony3 上安装 FOSUserBundle 时出现此错误。

[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException] 服务“security.authentication.manager”依赖于不存在的服务“security.user.provider.concrete.fos_userbundle”。 这是我的security.yml

security:

# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
    in_memory:
        memory: ~
encoders:
    FOS\UserBundle\Model\UserInterface: bcrypt

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    #dev:
    #    pattern: ^/(_(profiler|wdt)|css|images|js)/
    #    security: false

    main:
        anonymous: true
        pattern: ^/
        form_login:
            provider: fos_userbundle
            login_path: /login
            check_path: fos_user_security_check
            # if you are using Symfony < 2.8, use the following config instead:
            # csrf_provider: form.csrf_provider

        logout:       true
        anonymous:    true
        # activate different ways to authenticate

        # http_basic: ~
        # http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate

        # form_login: ~
        # http://symfony.com/doc/current/cookbook/security/form_login_setup.html

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 }
    - { path: ^/chat, role: ROLE_ADMIN }

【问题讨论】:

  • 我认为这个包还没有为 Symfony3 做好准备。引用文档“FOSUserBundle 在 Symfony2 中增加了对数据库支持的用户系统的支持”
  • 表示暂时不能使用这个捆绑包?
  • 就是这样。是时候建立一个 Symfony2 项目了吗?最新版本具有 Symfony 3.0 提供的所有功能,这意味着您只会丢失从 3.0 到 3.0.4 的新功能。
  • 哦,但是看那个!似乎有一种解决方法...stackoverflow.com/questions/34320624/…

标签: php fosuserbundle symfony


【解决方案1】:

您的 security.yml 文件中有两个 providers 键,这意味着永远不会加载第二个键(由 YAML 规范指定)。因此,您的应用程序对 FOSUserBundle 用户提供程序一无所知,而只知道您的内存中用户提供程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-12
    • 2013-04-25
    • 2019-01-23
    • 2014-09-11
    • 2013-12-24
    • 2020-02-27
    相关资源
    最近更新 更多