[英]Symfony 4: You have requested a non-existent parameter "locale"
When I enable the 'dev' mode in my Symfony 4 app (that is already online in a shared hosting service) it shows this message:当我在我的 Symfony 4 应用程序(已经在共享托管服务中在线)中启用“开发”模式时,它会显示以下消息:
(1/1) ParameterNotFoundException
You have requested a non-existent parameter "locale".
in ParameterBag.php (line 100)
at ParameterBag->get('locale')
in EnvPlaceholderParameterBag.php (line 57)
at EnvPlaceholderParameterBag->get('locale')
in ParameterBag.php (line 216)
at ParameterBag->resolveString('%locale%', array('locale' => true))
in ParameterBag.php (line 187)
...
and does not allow to debug the app.并且不允许调试应用程序。 My config/services.yml code is as default:我的 config/services.yml 代码是默认的:
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'en'
services:
# default configuration for Services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your Services.
autoconfigure: true # Automatically registers your Services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused Services; this also means
# fetching Services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
...
Please, someone can help me to fix this error.拜托,有人可以帮我解决这个错误。
Had the same problem during the fresh symfony 4.3 + sonata admin bundle installation.在新的 symfony 4.3 + 奏鸣曲管理包安装过程中遇到了同样的问题。 As a solution I added locale parameter:作为解决方案,我添加了 locale 参数:
// /config/services.yaml
parameters:
locale: 'en'
While I am not a Symphony expert the documentation appears to allow anything in the parameters section, but it does mention also defining the values in the .env.dist file as well for them to be used here.虽然我不是 Symphony 专家,但文档似乎允许参数部分中的任何内容,但它确实提到还定义了 .env.dist 文件中的值,以便在此处使用它们。
http://symfony.com/doc/current/best_practices/configuration.html#canonical-parameters http://symfony.com/doc/current/best_practices/configuration.html#canonical-parameters
When upgrading from symfony 4.2 to symfony 4.4 I also got this error when composer commands.从 symfony 4.2 升级到 symfony 4.4 时,我在 composer 命令时也遇到了这个错误。
This parameter seems so be used in config/packages/translation.yml
.这个参数似乎在config/packages/translation.yml
中使用。 Updating the symfony/translation
recipe which no longer refers to %locale% but hardcode 'en' solves the problem for me.更新不再引用 %locale% 但硬编码 'en' 的symfony/translation
配方为我解决了这个问题。
Simply run composer recipes:install symfony/translation --force -v
只需运行composer recipes:install symfony/translation --force -v
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.