Symfony 4:您请求的参数“locale”不存在

xqkwcwgp  于 2022-11-16  发布在  其他
关注(0)|答案(3)|浏览(169)

当我在我的Symfony 4应用程序中启用“dev”模式时(已经在共享主机服务中在线),它显示以下消息:

  1. (1/1) ParameterNotFoundException
  2. You have requested a non-existent parameter "locale".
  3. in ParameterBag.php (line 100)
  4. at ParameterBag->get('locale')
  5. in EnvPlaceholderParameterBag.php (line 57)
  6. at EnvPlaceholderParameterBag->get('locale')
  7. in ParameterBag.php (line 216)
  8. at ParameterBag->resolveString('%locale%', array('locale' => true))
  9. in ParameterBag.php (line 187)
  10. ...

并且不允许调试应用程序。我的config/services.yml代码是默认的:

  1. # Put parameters here that don't need to change on each machine where the app is deployed
  2. # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
  3. parameters:
  4. locale: 'en'
  5. services:
  6. # default configuration for Services in *this* file
  7. _defaults:
  8. autowire: true # Automatically injects dependencies in your Services.
  9. autoconfigure: true # Automatically registers your Services as commands, event subscribers, etc.
  10. public: false # Allows optimizing the container by removing unused Services; this also means
  11. # fetching Services directly from the container via $container->get() won't work.
  12. # The best practice is to be explicit about your dependencies anyway.
  13. ...

有人可以帮助我修复此错误。

1mrurvl1

1mrurvl11#

在新的symfony 4.3 + sonata管理包安装过程中遇到了同样的问题。作为解决方案,我添加了locale参数:

  1. // /config/services.yaml
  2. parameters:
  3. locale: 'en'
06odsfpq

06odsfpq2#

虽然我不是SymphonyMaven,但文档似乎允许在参数部分中进行任何操作,但它确实提到了在.env.dist文件中定义值,以及在这里使用它们。
http://symfony.com/doc/current/best_practices/configuration.html#canonical-parameters

qnyhuwrf

qnyhuwrf3#

当从symfony 4.2升级到symfony 4.4时,我在编写命令时也得到了这个错误。
这个参数似乎在config/packages/translation.yml中使用。更新symfony/translation方法,不再引用%locale%,而是硬编码'en',为我解决了这个问题。
只需运行composer recipes:install symfony/translation --force -v

相关问题