我对Symfony有疑问。我正在尝试将工厂用于控制器,但它不起作用。
#services.yml
services:
app.foo_controller_factory:
class: Foo\Controller\DefaultControllerFactory
arguments:
container: '@service_container'
app.foo_controller:
class: Foo\Controller\DefaultController
factory_class: '@app.foo_controller_factory'
factory_method: create_service
#/routing.yml
foo_bar:
path: /foo
defaults: { _controller: app.foo_controller:indexAction }
问题是因为应用程序永远不会通过DefaultControllerFactory。
可能是什么解决方案?
答案 0 :(得分:1)
我不得不修改services.yml
#services.yml
services:
app.foo_controller_factory:
class: Foo\BarBundle\Controller\DefaultControllerFactory
arguments:
container: '@service_container'
app.foo_controller:
class: Foo\BarBundle\Controller\DefaultController
factory: 'app.foo_controller_factory:createService'