リスナー内のデータベース情報にアクセスする必要があります。 私たちは、リスナーが似ているservice.yml でリスナーを設定します。私たちはonKernelRequest機能で教義にアクセスするにはどうすればよい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)
{
...
?
私は、コントローラから延びており、実行しようとしました:
$em = $this->getDoctrine()->getEntityManager();
、それは動作しますが、私はこれは悪い習慣だと思います。
すべてのコメントに感謝します。すべてが良いオプションです。 – Santi