How can I inject a service (created service) into my controller? Setter injection will do.
<?php namespace MyNamespace; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class MyController extends Controller { public function setMyService(MyService $myService) { $this->myService = $myService; } public function indexAction() {
And my route settings:
// Resources/routing.yml myController_index: pattern: /test defaults: { _controller: "FooBarBundle:MyController:index" }
I install the service in another package:
// Resources/services.yml parameters: my.service.class: Path\To\My\Service services: my_service: class: %my.service.class%
When a route is allowed, the service is not entered (I know that it should not). I assume that somewhere in the yml file, I should install:
calls: - [setMyService, [@my_service]]
I do not use this controller as a service, it is a regular controller that serves the request.
Edit: at the moment I am getting a service with $ this-> container-> get ('my_service'); But I need to enter it.
source share