我无法从奏鸣曲安装用户包

I can't install the user bundle from sonata

我正在尝试使用 symfony 奏鸣曲安装用户包:

composer require sonata-project/user-bundle

遵循以下文档:

https://sonata-project.org/bundles/user/4-x/doc/reference/installation.html

但它总是给我带来错误

Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 1
!!
!!  In ArrayNode.php line 224:
!!
!!    The child node "db_driver" at path "fos_user" must be configured.
!!
!!
!!

这是我的 composer.json 文件

{
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": ">=7.1.3",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "composer/package-versions-deprecated": "1.11.99.1",
        "doctrine/annotations": "^1.0",
        "doctrine/doctrine-bundle": "^2.2",
        "doctrine/doctrine-migrations-bundle": "^3.0",
        "doctrine/orm": "^2.8",
        "phpdocumentor/reflection-docblock": "^5.2",
        "sensio/framework-extra-bundle": "^5.1",
        "sonata-project/admin-bundle": "^3.90",
        "sonata-project/doctrine-orm-admin-bundle": "^3.30",
        "symfony/asset": "4.4.*",
        "symfony/console": "4.4.*",
        "symfony/dotenv": "4.4.*",
        "symfony/expression-language": "4.4.*",
        "symfony/flex": "^1.3.1",
        "symfony/form": "4.4.*",
        "symfony/framework-bundle": "4.4.*",
        "symfony/http-client": "4.4.*",
        "symfony/intl": "4.4.*",
        "symfony/mailer": "4.4.*",
        "symfony/monolog-bundle": "^3.1",
        "symfony/process": "4.4.*",
        "symfony/property-access": "4.4.*",
        "symfony/property-info": "4.4.*",
        "symfony/proxy-manager-bridge": "4.4.*",
        "symfony/security-bundle": "4.4.*",
        "symfony/serializer": "4.4.*",
        "symfony/translation": "4.4.*",
        "symfony/twig-bundle": "^4.4",
        "symfony/validator": "4.4.*",
        "symfony/web-link": "4.4.*",
        "symfony/yaml": "4.4.*",
        "twig/extra-bundle": "^2.9",
        "twig/twig": "^2.9"
    },
    "require-dev": {
        "symfony/browser-kit": "^4.4",
        "symfony/css-selector": "^4.4",
        "symfony/debug-bundle": "^4.4",
        "symfony/maker-bundle": "^1.0",
        "symfony/phpunit-bridge": "^5.2",
        "symfony/stopwatch": "^4.4",
        "symfony/var-dumper": "^4.4",
        "symfony/web-profiler-bundle": "^4.4"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\Tests\": "tests/"
        }
    },
    "replace": {
        "paragonie/random_compat": "2.*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "4.4.*"
        }
    }
}

在出现此错误之前,还有一个错误告诉我将 twig 版本更改为旧版本,因此 首先我改变了 twig/extra-bundle": "^2.12|^3.0" twig/twig": "^2.12|^3.0"

到twig/extra-bundle": "^2.9","twig/twig": "^2.9"

然后发生这种情况,我该怎么办?

只需将此配置添加到配置文件,转到此路径 app/config/config.yml,然后将此行添加到 config.yml 文件的末尾

# app/config/config.yml
fos_user:
     db_driver: orm # other valid values are 'mongodb' and 'couchdb'
     firewall_name: main
     user_class: UserBundle\Entity\User
     from_email:
         address: "%mailer_user%"
         sender_name: "%mailer_user%"

尝试在包中创建 fos_user.yaml 并添加此代码

fos_user.yaml

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: Entity\User
    from_email:
        address: "%mailer_user%"
        sender_name: "%mailer_user%"

并在您的 framework.yaml 中添加此代码 framework.yaml

framework:
    templating:
        engines: ['twig', 'php']

所以这就是我为使它最终起作用所做的工作 首先我在 config/packages/fos_user.yaml 中创建了一个 fos_user.yaml 文件,像这样

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: App\Entity\SonataUserUser
    group:
        group_class: App\Entity\SonataUserGroup
        group_manager: sonata.user.orm.group_manager
    service:
        user_manager: sonata.user.orm.user_manager
    from_email:
        address: "%mailer_user%"
        sender_name: "%mailer_user%"

然后我像这样在 config/service.yaml 中创建了参数 %mailer_user%

parameters:
    mailer_user: -

最后我把这个添加到 framework.yaml

framework:
    templating:
            engines: ['twig', 'php']

它安装成功,但我必须手动添加奏鸣曲文档中存在的剩余文件和配置以及其他代码。

感谢您的帮助