2016-02-26 61 views
-1

我有一個小問題。我已經覆蓋了app/Resources/TwigBundle/views/Exception/中的模板,並分別出現錯誤,錯誤404和錯誤500.html.twig。 我已經刪除緩存並在一個未定義的頁面,我得到的打算:Symfony拋出ResourceNotFoundException與重寫的錯誤模板

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.

我在想什麼?

+0

你有'503服務不可用'。嘗試爲非** 404 **和** 500 **錯誤創建'error.html.twig' tempalte。 – Dmitry

+0

我已經有了。看來,如果我刪除除了那個之外的所有內容並清除它的緩存,它就可以工作。我會更多地關注它。 –

+0

好的。嘗試爲產品環境啓用調試模式 - 應該有更詳細的錯誤跟蹤。 – Dmitry

回答

0

我發現了錯誤,很抱歉。

的問題是錯誤的模板被調用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 %} 

而在父模板,我要求令牌存儲。

爲將來學好東西。