Friday, July 22, 2016

Accessing other Services

When extending the base controller class, you can access any Symfony service via the get()method of the Controller class. Here are several common services you might need:
1
2
3
4
5
$templating = $this->get('templating');

$router = $this->get('router');

$mailer = $this->get('mailer');
What other services exist? To list all services, use the debug:container console command:
1
$ php bin/console debug:container
For more information, see the Service Container chapter.
To get a container configuration parameter in controller you can use thegetParameter() method:
$from = $this->getParameter('app.mailer.from');

No comments: