【发布时间】:2012-08-23 04:42:02
【问题描述】:
我将参数定义为:
parameters:
config1:
title: Title 1
data_proc: getDataOne
options: [things, stuff]
config2:
title: Title 2
data_proc: getDataTwo
options: [things, stuff]
#...
一个服务定义为
my_service:
class: Me\MyBundle\Services\MyService
arguments:
- @security.context
- @doctrine.dbal.my_connection
- %config% # the parameter that I'd like to be dynamic
控制者喜欢
class ProduitController extends Controller
{
public function list1Action()
{
$ssrs = $this->get('my_service'); // with config1 params
# ...
}
public function list2Action()
{
$ssrs = $this->get('my_service'); // with config2 params
# ...
}
#...
}
多个控制器使用my_service。
我的list1Action() 应该通过仅注入config1 参数来调用my_service
如何在不必定义与控制器一样多的服务的情况下做到这一点?
【问题讨论】:
-
你们有哪些服务?您尝试注入哪个控制器?请让您的问题更加清晰