2015-01-11 59 views
0

我创建的文件自定义错误模板抛出致命错误

/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 %} 

这是我如何在我的应用程序扩展所有的模板,它的工作没有任何问题。但它不适用于错误处理。我总是收到此错误信息:

Fatal error: Uncaught exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' with message 'Unable to find entity.' in C:\xampp\htdocs\myapp\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php:218 Stack trace: #0 C:\xampp\htdocs\myapp\src\myapp\MyappBundle\Controller\AddressController.php(207): Symfony\Bundle\FrameworkBundle\Controller\Controller->createNotFoundException('Unable to find ...') #1 [internal function]: myapp\MyappBundle\Controller\AddressController->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->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #4 C:\xampp\htdocs\myapp\app\bootstrap.php.cache(3131): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #5 C:\xampp\htdocs\myapp\app\bootstrap.php.cache(2376) in C:\xampp\htdocs\myapp\app\bootstrap.php.cache on line 2998

这是我扔的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,我得到这个错误信息:

The merge filter only works with arrays or hashes; NULL and array given in TwigBundle:Exception:error.html.twig at line 1.

我不使用twig_array_merge可言。

更新2

这是由path()电话,我合并_route_params在我footer.html.twig_locale,我从我的MyappBundle::base.html.twig文件包括引起:

<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

Mayby在base.html.twig twig_array_merge掷错误? ... – Gregsparrow

+0

不,我根本不使用twig_array_merge。 –

+0

@Gregsparrow走在正确的轨道上。我可以用'MyappBundle :: base.html.twig''重现错误。尝试将基本模板移入您的包中,例如''MyappBundle:默认:base.html.twig'' – geoB

回答

1

的最简单的解决方案,虽然不一定是最可取的,是修改线中更新2如下:

{% if app.request.get('_route_params') is not null %} 
<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> 
{% endif %} 
+0

这有帮助,是的。虽然这只是一个解决方法(这可能是一个错误)。 –