Doctrine 2 is an independent third-party library that encapsulates PDO. When PDO encounters a uniqueness conflict, it throws a PDOException.
Under the default configuration, the error page of the development environment catches this PDOException and outputs a Message.
There are two ways to redefine the error page of Symfony 2:
(1) Create an app/Resources/TwigBundle/views/Exception/error.html.twig and modify it according to your needs.
There are statustext, statuscode and other data available in the template.
(2) Or just use Event to listen for the kernel.exception event:
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpFoundation\Response;
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
// 你已经获得了Exception:可以针对性地写逻辑
$response = new Response();
$event->setResponse($response); // 如果你在event里设置了response,这个response就会返回给用户
// ...
}
The template of Symfony's The Book has been written very clearly. It will first check whether there is such a template under app/Resources. If not, it will go to the Bundle.
The most important thing is to clear the cache for it to work
Doctrine 2 is an independent third-party library that encapsulates PDO. When PDO encounters a uniqueness conflict, it throws a PDOException.
Under the default configuration, the error page of the development environment catches this PDOException and outputs a Message.
There are two ways to redefine the error page of Symfony 2:
(1) Create an app/Resources/TwigBundle/views/Exception/error.html.twig and modify it according to your needs.
There are statustext, statuscode and other data available in the template.
(2) Or just use Event to listen for the kernel.exception event:
http://symfony.com/doc/current/book/internals.html#kernel-kernel-exception
The template of Symfony's The Book has been written very clearly. It will first check whether there is such a template under app/Resources. If not, it will go to the Bundle. The most important thing is to clear the cache for it to work