【问题标题】:Symfony 3.4 - non existent service when installing FOSUserBundleSymfony 3.4 - 安装 FOSUserBundle 时服务不存在
【发布时间】:2019-02-28 08:50:09
【问题描述】:

我刚刚使用 Symfony 3.4 开始了一个新的空白项目,首先在 Documentation 页面之后配置了 FOSUserBundle。

我尝试了两次全部删除并重新从头开始,但在清除缓存时出现此错误:

In CheckExceptionOnInvalidReferenceBehaviorPass.php line 31:

  The service "security.authentication.provider.dao.main" has a dependency on a non-existent service "fos_user.user_checker". 

config.yml

[...]
fos_user:
    db_driver: orm # other valid values are 'mongodb' and 'couchdb'
    firewall_name: main
    user_class: AppBundle\Entity\User
    from_email:
        address: "%mailer_user%"
        sender_name: "%mailer_user%"

parameters.yml

parameters:
    database_path: '%kernel.project_dir%/var/data/data.sqlite'
    mailer_transport: smtp
    mailer_host: smtp.mailtrap.io
    mailer_user: ***
    mailer_password: ***
    secret: ***

routing.yml

app:
    resource: '@AppBundle/Controller/'
    type: annotation
fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"

security.yml

security:
    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:
        main:
            pattern: ^/
            user_checker: fos_user.user_checker
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager

            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 }

显然我在AppKernel.php 中添加了new FOS\UserBundle\FOSUserBundle(),

$bundles = [
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new AppBundle\AppBundle(),
        ];

我正在使用FOSUserBundleSymfony 3.4 的版本2.0

【问题讨论】:

  • 您是否尝试过将user_checker: fos_user.user_checkersecurity.yml 注释掉并刷新?
  • 该死,这解决了错误。但是..为什么文档中有这个参数?
  • 我也问同样的问题...为什么在文档中...:S

标签: php symfony fosuserbundle


【解决方案1】:

对于 Symfony 3.4 和 FOSUserBundle 2.1,这个问题似乎继续存在。

修复: 在 security.yml 中更改以下内容

security:
    firewalls:
        main:
            user_checker: fos_user.user_checker

security:
    firewalls:
        main:
            user_checker: security.user_checker

【讨论】:

    猜你喜欢
    • 2019-01-23
    • 2018-11-02
    • 1970-01-01
    • 2018-10-10
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多