Chúng tôi cần truy cập vào thông tin cơ sở dữ liệu trong một người nghe. Chúng tôi cấu hình người nghe trong một service.yml Người nghe cũng giống như:Truy cập vào cơ sở dữ liệu trong một người nghe trong 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)
{
...
Làm thế nào chúng ta có thể tiếp cận với học thuyết tại chức năng onKernelRequest?
tôi cố gắng kéo dài từ bộ điều khiển và làm:
$em = $this->getDoctrine()->getEntityManager();
và nó hoạt động nhưng tôi nghĩ rằng đây là một thực tế xấu.
Nhờ tất cả ý kiến. Tất cả đều là lựa chọn tốt. – Santi