php Symfony2:您请求了一个不存在的参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33023299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:20:01  来源:igfitidea点击:

Symfony2: You have requested a non-existent parameter

phpsymfonyopenshift

提问by Jér?me Verstrynge

I have checked similar questions on SO, but they did not solve my issue.

我在 SO 上检查了类似的问题,但他们没有解决我的问题。

I am deploying a Symfony2 application on Openshift. It works well on my Windows 10 laptop, but I am getting the following error messageon Openshift:

我正在 Openshift 上部署一个 Symfony2 应用程序。它在我的 Windows 10 笔记本电脑上运行良好,但我在 Openshift 上收到以下错误消息

Fatal error: Uncaught exception 'Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException'
with message 'You have requested a non-existent parameter "database_path".
Did you mean one of these: "database_host", "database_port", "database_name", "database_user"?'
in /var/lib/openshift/55eed4837628e1199f0000bb/app-root/runtime/repo/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:106 Stack trace: #0 
/var/lib/openshift/55eed4837628e1199f0000bb/app-root/runtime/repo/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php(248):
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->get('database_path') #1 [internal function]:
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->Symfony\Component\DependencyInjection\ParameterBag\{closure}(Array) #2
/var/lib/openshift/55eed4837628e1199f0000bb/app-root/runtime/repo/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php in
/var/lib/openshift/55eed4837628e1199f0000bb/app-root/runtime/repo/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php on line 106

My config.ymlis:

我的config.yml是:

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

doctrine:
    dbal:
        driver:   pdo_sqlite
        charset:  UTF8
        path:     "%kernel.root_dir%/../%database_path%"
...

My parameters.ymlis:

我的parameters.yml是:

parameters:
    database_driver: pdo_sqlite
    database_host: localhost
    database_port: null
    database_name: demo.db
    database_user: root
    database_password: null
    database_path: /data/demo.db
    ...

and my config_prod.ymlis:

我的config_prod.yml是:

imports:
    - { resource: config.yml }
...

What am I doing wrong?

我究竟做错了什么?

Update

更新

I have changed my config.ymlto:

我已更改config.yml为:

path:     "%kernel.root_dir%/../data/demo.db"

and the issue is gone, but I don't know why!

问题消失了,但我不知道为什么!

回答by felipsmartins

This is a common mistake.

这是一个常见的错误。

Just like I have commented above:
When running composerinstall, symfony will regenerate a new parameters.ymlfile based on parameters.yml.dist(if any).
So it's a good idea always check if parameters.ymlgenerated by symfony (on post install event, composer) is okay.

就像我上面评论的那样:
运行composerinstall 时,symfony 将parameters.yml根据parameters.yml.dist(如果有)重新生成一个新文件。
因此,最好始终检查parameters.ymlsymfony 生成的(在安装后事件中,作曲家)是否正常。

Also:

还:

Whenever you update the parameters.ymlfile (with configs that should be in the prod server also well), you must update the file parameters.yml.disttoo.

每当您更新parameters.yml文件时(配置也应该在生产服务器中),您也必须更新文件 parameters.yml.dist

So the deployment process will be much less painful.

所以部署过程会少很多痛苦。