Custom error template throws fatal error

Gottlieb Notschnabel

I created the file

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

with this content

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

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

This is how I extend all templates in my app, and it works without any problem. But it doesn't work for the error handling. I always get this error message:

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

This is how I throw the 404 error:

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

I am using Win7 with PHP v5.5.6 and Symfony v2.6.3. When running on my production server, I get a blank page (no sourcecode at all). And –surely– I've cleared my cache.

Update

When I try to preview my error page in dev mode, I get this error message:

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

I don't use twig_array_merge at all.

Update 2

This is caused by a path() call where I merge the _route_params and the _locale in my footer.html.twig that I include from my MyappBundle::base.html.twig file:

<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>

It works on all my templates except on the error template. What is wrong here, how can I fix that?

geoB

The simplest solution, although not necessarily the most desirable, is to modify the line in Update 2 as follows:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

App Throws Fatal Error, then reboots and works

From Dev

fatal error using custom library

From Dev

django template throws NoReverseMatch error

From Dev

django template throws NoReverseMatch error

From Dev

Custom template namespace error

From Dev

Fatal error: use of unimplemented initializer in custom navigationcontroller

From Dev

Add Custom UIButton Programmatically fatal error

From Dev

Parenthesis in Spacebars template helper call throws error

From Dev

Why does a semicolon in ejs template throws error

From Dev

AngularJs template url loading throws CORS error

From Dev

Parenthesis in Spacebars template helper call throws error

From Dev

Taking a datetime field into primary key throws fatal error

From Dev

Server suddenly throws out a fatal error, after dos attack

From Dev

Swift distance() method throws fatal error: can not increment endIndex

From Dev

Mustache.php with JSON data throws Catchable fatal error

From Dev

go get throws 'fatal error: unexpected signal during runtime execution'

From Dev

fullCalendar custom events function throws not a function error

From Dev

iterator on custom classes in python throws error in python

From Dev

notify_airbrake throws error on custom classes

From Dev

FATAL ERROR : main error

From Dev

Fatal error: Uncaught Error

From Dev

Clang. Fatal error: recursive template instantiation exceeded maximum depth

From Dev

c++ fatal error C1001 on using variadic template

From Dev

Else condition in template file creating fatal error in plugin file

From Dev

Fatal error : Cannot use [] for reading using smarty template

From Dev

Swift UITableViewCell detailTextLabel.text throws error 'fatal error: Can't unwrap Optional.None'

From Dev

Custom TableView cell dequeue fatal error: unexpectedly found nil

From Dev

Calling a service on a custom class returns Catchable Fatal Error in Symfony

From Dev

Magento custom shipping module - Fatal error: Call to a member function setStore()

Related Related

  1. 1

    App Throws Fatal Error, then reboots and works

  2. 2

    fatal error using custom library

  3. 3

    django template throws NoReverseMatch error

  4. 4

    django template throws NoReverseMatch error

  5. 5

    Custom template namespace error

  6. 6

    Fatal error: use of unimplemented initializer in custom navigationcontroller

  7. 7

    Add Custom UIButton Programmatically fatal error

  8. 8

    Parenthesis in Spacebars template helper call throws error

  9. 9

    Why does a semicolon in ejs template throws error

  10. 10

    AngularJs template url loading throws CORS error

  11. 11

    Parenthesis in Spacebars template helper call throws error

  12. 12

    Taking a datetime field into primary key throws fatal error

  13. 13

    Server suddenly throws out a fatal error, after dos attack

  14. 14

    Swift distance() method throws fatal error: can not increment endIndex

  15. 15

    Mustache.php with JSON data throws Catchable fatal error

  16. 16

    go get throws 'fatal error: unexpected signal during runtime execution'

  17. 17

    fullCalendar custom events function throws not a function error

  18. 18

    iterator on custom classes in python throws error in python

  19. 19

    notify_airbrake throws error on custom classes

  20. 20

    FATAL ERROR : main error

  21. 21

    Fatal error: Uncaught Error

  22. 22

    Clang. Fatal error: recursive template instantiation exceeded maximum depth

  23. 23

    c++ fatal error C1001 on using variadic template

  24. 24

    Else condition in template file creating fatal error in plugin file

  25. 25

    Fatal error : Cannot use [] for reading using smarty template

  26. 26

    Swift UITableViewCell detailTextLabel.text throws error 'fatal error: Can't unwrap Optional.None'

  27. 27

    Custom TableView cell dequeue fatal error: unexpectedly found nil

  28. 28

    Calling a service on a custom class returns Catchable Fatal Error in Symfony

  29. 29

    Magento custom shipping module - Fatal error: Call to a member function setStore()

HotTag

Archive