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

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

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

(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)
...

并且不允许调试应用程序。我的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.
...

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

1mrurvl1

1mrurvl11#

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

// /config/services.yaml

parameters:
    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

相关问题