在database_driver上获取[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]错误

How*_*own 7 install composer-php symfony-2.8

当我运行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"?
Run Code Online (Sandbox Code Playgroud)

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

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

**为了成功运行'composer install命令,我需要更改什么?

注意:我还看到'composer install'命令的下面输出说我的composer.lock文件已经过时并且运行'composer update'命令,但是当我这样做时,它会因内存不足而失败错误,这是没有意义的,因为我在服务器上有三个内存,超过28演出的免费磁盘空间!如果可能的话,我想首先尝试解决"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"?
Run Code Online (Sandbox Code Playgroud)

这是我的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: ############################
Run Code Online (Sandbox Code Playgroud)

这是我的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:                  #######################
Run Code Online (Sandbox Code Playgroud)

这是我的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 }
Run Code Online (Sandbox Code Playgroud)

这是我的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:  ###@####.###
Run Code Online (Sandbox Code Playgroud)

最后,这是我的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"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

bha*_*adi 1

@霍华德·布朗

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

我想每当我们更新parameters.yml(配置也应该在产品服务器上)时,您也必须更新文件parameters.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
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息