10
We need to access to database info in a listener. We configure the listener in a service.yml The listener is like:
namespace company\MyBundle\Listener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class RequestListener
{
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function onKernelRequest(GetResponseEvent $event)
{
...
How can we access to doctrine at onKernelRequest function?
I tried to extends from controller and do:
$em = $this->getDoctrine()->getEntityManager();
and it works but I think this is a bad practice.