自定义错误模板会引发致命错误

时间:2015-01-11 13:28:22

标签: php symfony error-handling http-status-code-404

我创建了文件

/myapp/app/Resources/TwigBundle/views/Exception/error.html.twig

有了这个内容

{% extends 'MyappBundle::base.html.twig' %}

{% block body %}
<div>
    <h1>Error</h1>
    <p>The server returned a "{{ status_code }} {{ status_text }}".</p>
</div>
{% endblock %}

这就是我在我的应用中扩展所有模板的方式,它没有任何问题。但它不适用于错误处理。我总是收到此错误消息:

  

致命错误:未捕获异常'Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException',消息'无法找到实体'。在C:\ xampp \ htdocs \ myapp \ vendor \ symfony \ symfony \ src \ Symfony \ Bundle \ FrameworkBundle \ Controller \ Controller.php:218堆栈跟踪:#0 C:\ xampp \ htdocs \ myapp \ src \ myapp \ MyappBundle \ Controller \ AddressController.php(207):Symfony \ Bundle \ FrameworkBundle \ Controller \ Controller-&gt; createNotFoundException('无法找到...')#1 [内部函数]:myapp \ MyappBundle \ Controller \ AddressController-&gt; showAction('= k21RBNjM')#2 C:\ xampp \ htdocs \ myapp \ app \ bootstrap.php.cache(3020):call_user_func_array(Array,Array)#3 C:\ xampp \ htdocs \ myapp \ app \ bootstrap。 php.cache(2982):Symfony \ Component \ HttpKernel \ HttpKernel-&gt; handleRaw(Object(Symfony \ Component \ HttpFoundation \ Request),1)#4 C:\ xampp \ htdocs \ myapp \ app \ bootstrap.php.cache (3131):Symfony \ Component \ HttpKernel \ HttpKernel-&gt; handle(Object(Symfony \ Component \ HttpFoundation \ Request),1,true)#5 C:\ xampp \ htdocs \ myapp \ app \ bootstrap.php.cache( 2376)在第2998行的C:\ xampp \ htdocs \ myapp \ app \ bootstrap.php.cache

这就是我抛出404错误的方法:

$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('MyBundle:Entity')->find($id);
if (!$entity) {
    throw $this->createNotFoundException('Unable to find entity.');
}

我正在使用Win7与PHP v5.5.6和Symfony v2.6.3。在我的生产服务器上运行时,我得到一个空白页面(根本没有源代码)。而且 - 当然 - 我已经清理了我的缓存。

更新

当我尝试preview my error page in dev mode时,收到以下错误消息:

  

合并过滤器仅适用于数组或散列; TwigBundle中给出的NULL和数组:异常:第1行的error.html.twig。

我根本不使用twig_array_merge

更新2

这是由path()调用引起的,我将_route_params和我_locale中的footer.html.twig合并到我的MyappBundle::base.html.twig文件中:< / p>

<a href="{{ path(app.request.get('_route'), app.request.get('_route_params')|merge({'_locale': lang})) }}"><span class="flag-icon flag-icon-{{ lang }}"></span> {{ lang }}</a>

除错误模板外,它适用于我的所有模板。这里有什么问题,我该如何解决?

0 个答案:

没有答案
相关问题