There are some articles around which touch this topic, but none of them seemed to be a practical usable solution for me. My goal is to put some basic methods (those I need in each controller anyway) into a basecontroller, e.g.
$this->getEntityManager();
$this->getRequest();
$this->getRepository($entityName);
How can this be done?
AFAIK we have to inject the services into the basecontroller, but how do I tell classes to use a service for their superclass? There is some decent article about Controllers and Dependency Injection [1], but finally I got stuck with that approach too, see my comment here: [2]
[1] http://miller.limethinking.co.uk/2011/04/15/symfony2-controller-as-service/
[2] http://miller.limethinking.co.uk/2011/04/15/symfony2-controller-as-service/#comment-579
pseudocode
MyBaseController impliments Symfony\Component\Di\ContainerAwareInterface
setContainer($container)
$this->container = $container
getEntityManager
return $this->container->get('doctrine.orm.entity_manager')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With