我尝试使用 onKernelRequest 进行自定义侦听器,但出现此错误致命错误:调用未定义方法 appDevDebugProjectContainer::generate()
我的服务是:
services:
kernel.listener.Configurazione:
class: My\ConfigurazioneBundle\Listener\Configurazione
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
arguments: [@security.context,@router,@service_container]
我的听众是:
namespace My\ConfigurazioneBundle\Listener;
use My\ConfigurazioneBundle\Event\ConfigurazioneEvent;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class Configurazione {
protected $sicurezza;
protected $router;
protected $container;
function __construct(SecurityContextInterface $securityContext, $container, $router) {
$this->sicurezza = $securityContext;
$this->container = $container;
$this->router = $router;
}
public function onKernelRequest(GetResponseEvent $event) {
$user = $this->sicurezza->getToken()->getUser();
$container = $this->container;
$url = $this->router->generate('homepage');
}
}
我有这个错误
致命错误:调用未定义的方法 appDevDebugProjectContainer::generate()
我的 composer.json
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.8",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.1.*",
"twig/extensions": "1.0.*@dev",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.1.*",
"symfony/monolog-bundle": "2.1.*",
"sensio/distribution-bundle": "2.1.*",
"sensio/framework-extra-bundle": "2.1.*",
"sensio/generator-bundle": "2.1.*",
"jms/security-extra-bundle": "1.2.*",
"jms/di-extra-bundle": "1.1.*",
"kriswallsmith/assetic": "1.1.*@dev",
"stof/doctrine-extensions-bundle": "dev-master",
"friendsofsymfony/user-bundle": "*",
"punkave/symfony2-file-uploader-bundle":"*",
"willdurand/expose-translation-bundle": "dev-master",
"apy/jsfv-bundle":"dev-master",
"cypresslab/compass-elephant-bundle":"dev-master",
},