Symfony 4:您已经请求了一个不存在的参数“locale”

时间:2018-02-13 16:27:16

标签: php symfony

当我在我的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.
...

请有人帮我解决此错误。

2 个答案:

答案 0 :(得分:1)

虽然我不是Symphony专家,但文档似乎允许参数部分中的任何内容,但它确实也提到了.env.dist文件中的值以及它们在此处使用的内容。

http://symfony.com/doc/current/best_practices/configuration.html#canonical-parameters

答案 1 :(得分:1)

在全新的symfony 4.3 +奏鸣曲admin软件包安装过程中遇到了相同的问题。 作为解决方案,我添加了语言环境参数:

// /config/services.yaml

parameters:
    locale: 'en'