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