If you look at these two methods in the Symfony\Bundle\FrameworkBundle\Controller\Controller class, you will see the service name and how to use them.
public function generateUrl($route, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { return $this->container->get('router')->generate($route, $parameters, $referenceType); } public function createForm($type, $data = null, array $options = array()) { return $this->container->get('form.factory')->create($type, $data, $options); }
Basically, you need router and form.factory to implement the functionality. I do not recommend passing the controller to your class. Controllers are special classes that are used mainly by the framework itself. If you plan to use your class as a service, just create one.
services: my_manager: class: Something\MyManager arguments: [@router, @form.factory]
Create a constructor with two arguments for the services and implement the necessary methods in your class.
class MyManager { private $router; private $formFactory; public function __construct($router, $formFactory) { $this->router = $router; $this->formFactory = $formFactory; }
source share