Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2-如何将服务传输到阵列中的另一个服务_Php_Symfony_Configuration_Dependency Injection - Fatal编程技术网

Php Symfony2-如何将服务传输到阵列中的另一个服务

Php Symfony2-如何将服务传输到阵列中的另一个服务,php,symfony,configuration,dependency-injection,Php,Symfony,Configuration,Dependency Injection,我无法将服务传输到阵列中的另一个服务 例如,这是我的config.yml: 服务: car.price.calculator: 类别:My\SuperBundle\CarCalculator 论点:“某物” 产品浏览器: 汽车: rest_客户端:“@car.price.calculator”#传递到您的服务(a)service.container并使用container获得另一个服务,或者可能不需要“(a)car.price.calculator”,但“%car.price.calculato

我无法将服务传输到阵列中的另一个服务

例如,这是我的
config.yml

服务:
car.price.calculator:
类别:My\SuperBundle\CarCalculator
论点:“某物”
产品浏览器:
汽车:

rest_客户端:“@car.price.calculator”#传递到您的服务(a)service.container并使用container获得另一个服务,或者可能不需要“(a)car.price.calculator”,但“%car.price.calculator%”xcompl-我不想传递整个容器,我只想注入我需要的服务基本上您可以使用编译器传递。(请参阅)您可以使用then addArgument。。。类似于
$definition->addArgument(新引用($container->getParameter('product.browser.rest_client'))请参见。我认为重命名服务时,您应该使用
setAlias
而不是
setParameter
,然后只使用
car.price.calculator
而不使用
@
class Calculator {

private $set;

public function __contruct(array $set) {
    $this->set = $set;
    var_dump($set);
}
   array (size=2)
     'rest_client' => string '@car.price.calculator' <- and here is a problem, it is a string, should be object