我们需要访问侦听器中的数据库信息。 我们配置监听器在service.yml 监听器是这样的:在Symfony 2的侦听器中访问数据库
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)
{
...
我们怎样才能在onKernelRequest功能访问的学说?
我试图从控制器延伸,并做到:
$em = $this->getDoctrine()->getEntityManager();
和它的作品,但我认为这是一个不好的做法。
感谢所有的意见。所有都是很好的选择。 – Santi 2012-01-13 15:09:57