Symfony2 Custom Error Exception Listener - Rendering templates or passing to a controller

前端 未结 2 1943
予麋鹿
予麋鹿 2021-01-06 16:23

I\'m trying to work out the best way of handling custom error pages within Symfony2.This includes 500 and 404\'s etc.

I can create my own custom templates (error404

2条回答
  •  耶瑟儿~
    2021-01-06 16:32

    The way I did to solve similar issue is: I dont know if it can help you out.

    const GENERIC_CODE = 550;
    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();
        if ($exception instanceof RedirectableException) {
            $request = $event->getRequest();
            $url = $exception->getUrl($this->_authentication['base']['url']);
            $response = new Response();
            $response->setStatusCode(self::GENERIC_CODE, AuthenticationException::GENERIC_MESSAGE);
            $response->setContent($url);
            $event->setResponse($response);
       }
    }
    

提交回复
热议问题