定义“参数”不支持配置密钥

时间:2018-09-18 13:49:09

标签: dependency-injection symfony4

我正在使用Symfony DI组件。我正在尝试将字符串参数传递给服务构造函数,如下所示:

services:
   parameters:
        config.directory: './../../../'
   _defaults:
        public: true
   settings:
        class: Bar\Foo\Service
        arguments: ['%config.directory%']

我通过以下方式编译容器:

$containerBuilder = new ContainerBuilder();
$loader = new YamlFileLoader($containerBuilder, new FileLocator($dir));
$loader->load('services.yaml');
$containerBuilder->compile();

例外:

  

致命错误:未被发现   Symfony \ Component \ DependencyInjection \ Exception \ InvalidArgumentException:   不支持定义配置键“ config.directory”   “参数”

1 个答案:

答案 0 :(得分:0)

参数应与服务处于同一级别:

parameters:
    config.directory: './../../../'
services:
  _defaults:
       public: true
  settings:
       class: Bar\Foo\Service
       arguments: ['%config.directory%']