How to access “service container” in Symfony2.
Dirty way, works anywhere:
$serviceContainer = $kernel->getContainer()->get('any service you want');?
But most people says you should do it as service, which in my world is not always possible, especially using __construct injection.
This way as setContainer
- [setContainer, ["@service_container"] ]
Or this way as __construct injection
You can also pass it from controller, always at your fingertips as
This entry was posted in PHP, Symfony3. Bookmark the permalink.
//Or better yet service container shortcut