【问题标题】:Getting [Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException] error on database_driver在 database_driver 上出现 [Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException] 错误
【发布时间】:2017-12-01 06:46:49
【问题描述】:

当我运行 php -d memory_limit=2G ../composer/composer.phar install 时,我收到关于不存在的参数“database_driver”参数的错误。但是,如果我从 parameters.yml 和 parameters.yml.dist 文件中删除所有引用,那么我的 Web 应用程序将失败并显示:

ParameterNotFoundException in ParameterBag.php line 84:
You have requested a non-existent parameter "database_driver".
Did you mean one of these: "database_name", "database_user"?

所以我很清楚我需要这个参数。

我在我的 parameters.ymlparameters.yml.dist 文件中定义了“database_driver”,它存在于我的 config.yml 文件。

**为了成功运行 'composer install 命令,我需要进行哪些更改?

注意:我还看到“composer install”命令的以下输出表明我的 composer.lock 文件已过期并运行“composer update”命令,但是当我这样做时,它会失败并显示内存不足错误,这没有意义,因为我在服务器上有 3 GB 的内存和超过 28 GB 的可用磁盘空间!如果可能,我想先尝试解决“database_driver”问题**

这是上面 'composter install' 命令的输出:

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file

Warning: The lock file is not up to date with the latest changes in
composer.json. You may be getting outdated dependencies. Run update to
update them.

Nothing to install or update
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

  [Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
  You have requested a non-existent parameter "database_driver". Did you
  mean one of these: "database_name", "database_user"?

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
handling the symfony-scripts event terminated with an exception

  [RuntimeException]
  An error occurred when executing the "'cache:clear --no-warmup'" command:

    [Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
    You have requested a non-existent parameter "database_driver". Did you
    mean one of these: "database_name", "database_user"?

这是我的 parameters.yml.dist 文件:

# This file is a "template" of what your parameters.yml file should look like
# Set parameters here that may be different on each deployment target of the app,
# e.g. development, staging, production.
# http://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration

parameters:
    database_driver:         pdo_mysql
    database_host:           127.0.0.1
    database_port:           3306
    database_name:           ##########
    database_user:           ##########
    database_password:       ##########

    # You should uncomment this if you want use pdo_sqlite
    database_path:           "%kernel.root_dir%/data.db3"

    mailer_transport:        smtp
    mailer_host:             smtp.sendgrid.net
    mailer_user:             #############
    mailer_password:         #############

    locale:                  en

    # A secret key that's used to generate certain security-related tokens
    secret: ############################

这是我的 parameters.yml 文件:

# This file is auto-generated during the composer install

parameters:
    database_driver:         pdo_mysql
    database_server_version: 15.1
    database_host:           127.0.0.1
    database_port:           3306
    database_name:           ##########
    database_user:           ##########
    database_password:       ##########
    database_charset:        UTF8

    # You should uncomment this if you want use pdo_sqlite
    database_path:           "%kernel.root_dir%/data.db3"

    mailer_transport:        smtp
    mailer_host:             smtp.sendgrid.net
    mailer_user:             ##########
    mailer_password:         ##########

    locale:                  en

    # A secret key that's used to generate certain security-related tokens
    secret:                  #######################

这是我的 config.yml 文件:

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }

# Put parameters here that don't need to change on each machine where the
# app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration

parameters:
    locale: en

framework:
    #esi:             ~
    #translator:      { fallbacks: ["%locale%"] }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    #serializer:      { enable_annotations: true }
    templating:
        engines: ['twig']
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # handler_id set to null will use default session handler from php.ini
        handler_id:  ~
    fragments:       ~
    http_method_override: true

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

# Doctrine Configuration
doctrine:
    dbal:
        driver:         "%database_driver%"
        server_version: "%database_server_version%"
        host:           "%database_host%"
        port:           "%database_port%"
        dbname:         "%database_name%"
        user:           "%database_user%"
        password:       "%database_password%"
        charset:        "%database_charset%"

        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

# Swiftmailer Configuration
##swiftmailer:
##    transport:   "%mailer_transport%"
##    host:        "%mailer_host%"
##    username:    "%mailer_user%"
##    password:    "%mailer_password%"
##    port :       “%mailer_port%”
##    encryption:  ~
##    spool:      { type: memory }

这是我的 config_dev.yml 文件:

imports:
    - { resource: config.yml }

framework:
    router:
        resource: "%kernel.root_dir%/config/routing_dev.yml"
        strict_requirements: true
    profiler: { only_exceptions: false }

web_profiler:
    toolbar: true
    intercept_redirects: true

monolog:
    handlers:
        main:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
            channels: [!event]
        console:
            type:   console
            channels: [!event, !doctrine]
        # uncomment to get logging in your browser
        # you may have to allow bigger header sizes in your Web server configuration
        #firephp:
        #    type:   firephp
        #    level:  info
        #chromephp:
        #    type:   chromephp
        #    level:  info

swiftmailer:
#    delivery_address:  ###@####.###

最后,这是我的 composer.json 文件的内容:

{
    "name": "symfony/framework-standard-edition",
    "license": "MIT",
    "type": "project",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-4": { "": "src/" },
        "classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
    },
    "require": {
        "php": ">=5.6.0",
        "symfony/symfony": "2.8.*",
        "doctrine/orm": "^2.4.8",
        "doctrine/doctrine-bundle": "~1.4",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~5.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "~2.0",
        "google/recaptcha": "~1.1",
        "sendgrid/sendgrid": "~5.5"
    },
    "require-dev": {
        "sensio/generator-bundle": "~3.0",
        "symfony/phpunit-bridge": "~2.7"
    },
    "scripts": {
        "symfony-scripts": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-install-cmd": [
            "@symfony-scripts"
        ],
        "post-update-cmd": [
            "@symfony-scripts"
        ]
    },
    "config": {
        "bin-dir": "bin",
        "platform": {
            "php": "5.6.0"
        }
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "2.8-dev"
        }
    }
}

感谢您对此问题的任何帮助。

【问题讨论】:

    标签: composer-php installation symfony-2.8


    【解决方案1】:

    @霍华德·布朗

    我已经通过在 parameter.ymlparameter.dist 中添加 database_driver 参数解决了这个问题

    我想每当我们更新 parameters.yml(配置也应该在 prod 服务器上)时,您也必须更新文件参数 .yml.dist。

    以下是 parameter.yml.dist 文件的示例结构

    示例:

    parameters:
        database_host: 127.0.0.1
        database_port: *****
        database_name: symfony
        database_user: root
        database_password: *****
        database_driver: mysql
    

    更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-01
      • 1970-01-01
      • 2018-08-18
      • 2021-04-28
      • 2021-06-10
      • 2019-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多