How to define error page in symfony2!
我想大声告诉你
我想大声告诉你 2017-05-16 16:45:16
0
2
803

When using doctrine2 and defining a unique company name, an error is prompted when submitting again. How to redefine this error page.

我想大声告诉你
我想大声告诉你

reply all(2)
迷茫

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就会返回给用户

    // ...
}

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template