2
我已经做了一些自定义的异常侦听器,所以在数据库表中我有旧的url,现在是404错误和另一个用户应该重定向的网址,当它会到达旧的网址。问题是DEV环境下的一切工作正常,但是我有问题让它在PROD环境中工作(它引发503服务不可用错误)。Symfony2:自定义异常侦听器不工作env
有人可能知道什么是错的吗?
services.yml:
services:
coupons.exception.action_listener:
class: Coupons\WebBundle\EventListener\ExceptionListener
arguments: [@service_container, @templating]
tags:
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
ExecptionListener:
namespace Coupons\WebBundle\EventListener;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
class ExceptionListener
{
/**
* @var ContainerInterface
*/
protected $container;
/**
* @var TwigEngine
*/
protected $templating;
/**
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container, TwigEngine $templating){
// assign value(s)
$this->container = $container;
$this->templating = $templating;
}
/**
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
// get exception
$exception = $event->getException();
// get path
$path = $event->getRequest()->getPathInfo();
$url = $event->getRequest()->getUri();
$repository = $this->container->get('doctrine')->getRepository('CouponsWebBundle:SeoNotFound');
$seonotfound = $repository->createQueryBuilder('s')
->where('s.urlFrom LIKE :url')
->andWhere('s.status = 1')
->setParameter('url', $url.'%')
->getQuery()
->getOneOrNullResult();
if($seonotfound != NULL){
$event->setResponse(new RedirectResponse($seonotfound->getUrlTo(),$seonotfound->getRedirectType()));
}
}
}
清除缓存?服务器日志中是否有任何内容? –