【问题标题】:Symfony throwing ResourceNotFoundException with overridden error templates [duplicate]Symfony 使用重写的错误模板抛出 ResourceNotFoundException [重复]
【发布时间】:2016-06-09 09:08:22
【问题描述】:

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

致命错误:在 E:\svn\medapp\app\cache\prod\appProdUrlMatcher.php:4044 中未捕获异常 'Symfony\Component\Routing\Exception\ResourceNotFoundException' 堆栈跟踪:#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 [内部函数]: 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', 对象(Symfony\Componen t\EventDispatcher\ContainerAwareEventDis 在 E:\svn\medapp\app\cache\prod\classes.php 5334 行 503 服务不可用

prod.log:

[2016-02-26 09:40:49] request.ERROR: 未捕获的 PHP 异常 Symfony\Component\HttpKernel\Exception\NotFoundHttpException:“否 找到“GET /asdasdas”的路线 E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php 第 176 行 {“异常”:“[对象] (Symfony\Component\HttpKernel\Exception\NotFoundHttpException(代码: 0): 找不到 \"GET /asdasdas\" 的路由 E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php:176, Symfony\Component\Routing\Exception\ResourceNotFoundException(代码: 0): 在 E:\svn\medapp\app\cache\prod\appProdUrlMatcher.php:4044)"} [] [2016-02-26 09:40:49] request.CRITICAL:处理时抛出异常 异常(Twig_Error_Runtime:在 模板的呈现(“令牌存储不包含 身份验证令牌。一个可能的原因可能是没有 为此 URL 配置了防火墙。”)在 “MedAppBundle:Default:base.html.twig”在第 95 行。 E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php 第 182 行) {"exception":"[object] (Twig_Error_Runtime(code: 0): 异常有 在渲染模板期间被抛出(\“令牌存储 不包含身份验证令牌。一个可能的原因可能是 没有为此 URL 配置防火墙。\") 在 \"MedAppBundle:Default:base.html.twig\" 第 95 行。 E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php:182, Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(代码: 0):令牌存储不包含认证令牌。一种可能 原因可能是没有为此 URL 配置防火墙。在 E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authorization\AuthorizationChecker.php:57)"} [] [2016-02-26 09:40:49] request.CRITICAL:未捕获的 PHP 异常 Twig_Error_Runtime:“渲染过程中抛出了异常 模板(“令牌存储不包含身份验证令牌。 一个可能的原因可能是没有为 此 URL。”)在第 95 行的“MedAppBundle:Default:base.html.twig”中。在 E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php 第 182 行 {"exception":"[object] (Twig_Error_Runtime(code: 0): 异常有 在渲染模板期间被抛出(\“令牌存储 不包含身份验证令牌。一个可能的原因可能是 没有为此 URL 配置防火墙。\") 在 \"MedAppBundle:Default:base.html.twig\" 第 95 行。 E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php:182, Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(代码: 0):令牌存储不包含认证令牌。一种可能 原因可能是没有为此 URL 配置防火墙。在 E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authorization\AuthorizationChecker.php:57, Symfony\Component\HttpKernel\Exception\NotFoundHttpException(代码: 0): 找不到 \"GET /asdasdas\" 的路由 E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php:176, Symfony\Component\Routing\Exception\ResourceNotFoundException(代码: 0): 在 E:\svn\medapp\app\cache\prod\appProdUrlMatcher.php:4044)"} [] [2016-02-26 09:40:49] request.CRITICAL:处理时抛出异常 异常(Twig_Error_Runtime:在 模板的呈现(“令牌存储不包含 身份验证令牌。一个可能的原因可能是没有 为此 URL 配置了防火墙。”)在 “MedAppBundle:Default:base.html.twig”在第 95 行。 E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php 第 182 行) {"exception":"[object] (Twig_Error_Runtime(code: 0): 异常有 在渲染模板期间被抛出(\“令牌存储 不包含身份验证令牌。一个可能的原因可能是 没有为此 URL 配置防火墙。\") 在 \"MedAppBundle:Default:base.html.twig\" 第 95 行。 E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php:182, Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(代码: 0):令牌存储不包含认证令牌。一种可能 原因可能是没有为此 URL 配置防火墙。在 E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authorization\AuthorizationChecker.php:57)"} []

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

哎呀!发生错误

服务器返回“404 Not Found”。

有些东西坏了。请让我们知道发生此错误时您在做什么。我们会尽快修复它。给您带来的不便,我们深表歉意。

我错过了什么?

【问题讨论】:

  • 你有503 Service Unavailable。尝试为非 404500 错误创建 error.html.twig tempalte。
  • 我已经有了。似乎如果我删除除此之外的所有内容并清除缓存,它就可以工作。我会进一步研究。
  • 好的。尝试为 prod 环境启用调试模式 - 应该有更详细的错误跟踪。

标签: php symfony symfony-routing


【解决方案1】:

我发现了错误,打扰了。

问题是错误模板为它们正在扩展的模板调用 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 %}

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

值得为将来学习的东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-15
    • 2017-04-10
    • 2016-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多