Symfony 抛出带有覆盖错误模板的 ResourceNotFoundException

Symfony throwing ResourceNotFoundException with overridden error templates

我有个小问题。我已经覆盖了 app/Resources/TwigBundle/views/Exception/ 中的模板并分别出现错误,error404 和 error500.html.twig。 我已经删除了缓存,在进入未定义的页面时我得到:

Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' in E:\svn\medapp\app\cache\prod\appProdUrlMatcher.php:4044 Stack trace: #0 E:\svn\medapp\app\cache\prod\classes.php(1433): appProdUrlMatcher->match('/asdasd') #1 E:\svn\medapp\app\cache\prod\classes.php(19616): Symfony\Component\Routing\Matcher\UrlMatcher->matchRequest(Object(Symfony\Component\HttpFoundation\Request)) #2 E:\svn\medapp\app\cache\prod\classes.php(2583): JMS\I18nRoutingBundle\Router\I18nRouter->matchRequest(Object(Symfony\Component\HttpFoundation\Request)) #3 [internal function]: Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher)) #4 E:\svn\medapp\app\cache\prod\classes.php(2352): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDis in E:\svn\medapp\app\cache\prod\classes.php on line 5334 503 Service Unavailable

prod.log:

[2016-02-26 09:40:49] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /asdasdas"" at E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php line 176 {"exception":"[object] (Symfony\Component\HttpKernel\Exception\NotFoundHttpException(code: 0): No route found for \"GET /asdasdas\" at E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php:176, Symfony\Component\Routing\Exception\ResourceNotFoundException(code: 0): at E:\svn\medapp\app\cache\prod\appProdUrlMatcher.php:4044)"} [] [2016-02-26 09:40:49] request.CRITICAL: Exception thrown when handling an exception (Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.") in "MedAppBundle:Default:base.html.twig" at line 95. at E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php line 182) {"exception":"[object] (Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.\") in \"MedAppBundle:Default:base.html.twig\" at line 95. at E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php:182, Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(code: 0): The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL. at E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authorization\AuthorizationChecker.php:57)"} [] [2016-02-26 09:40:49] request.CRITICAL: Uncaught PHP Exception Twig_Error_Runtime: "An exception has been thrown during the rendering of a template ("The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.") in "MedAppBundle:Default:base.html.twig" at line 95." at E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php line 182 {"exception":"[object] (Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.\") in \"MedAppBundle:Default:base.html.twig\" at line 95. at E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php:182, Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(code: 0): The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL. at E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authorization\AuthorizationChecker.php:57, Symfony\Component\HttpKernel\Exception\NotFoundHttpException(code: 0): No route found for \"GET /asdasdas\" at E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php:176, Symfony\Component\Routing\Exception\ResourceNotFoundException(code: 0): at E:\svn\medapp\app\cache\prod\appProdUrlMatcher.php:4044)"} [] [2016-02-26 09:40:49] request.CRITICAL: Exception thrown when handling an exception (Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.") in "MedAppBundle:Default:base.html.twig" at line 95. at E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php line 182) {"exception":"[object] (Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.\") in \"MedAppBundle:Default:base.html.twig\" at line 95. at E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php:182, Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(code: 0): The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL. at E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authorization\AuthorizationChecker.php:57)"} []

如果我删除或重命名 TwigBundle 模板,然后删除缓存,我会得到标准的 Symfony 错误页面:

Oops! An Error Occurred

The server returned a "404 Not Found".

Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

我错过了什么?

我发现了错误,抱歉打扰了。

问题是错误模板正在为它们正在扩展的模板调用 parent()

{% extends 'MedAppBundle:Default:base.html.twig' %}
{% block body %}
    {{ parent() }}
    <div class="container-fluid" >
        <div class="row" >
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 error-content" >
                <h1 class="error-title">404</h1>

                <h2 class="error-header2">Resource Not Found
                </h2>

                <p>The resource requested could not be found on this server!</p>

            </div>
        </div>
    </div>
{% endblock body %}

在父模板中我要求存储令牌。

为将来学习的好东西。