while twig {% render%} sin página de error symfony2

If I run the controller "normally" the (Booking) Controller throws an exception I get my custom 500 error page.

If I render the controller inside another template, like so:

{% render "BookingBundle:Booking:list" %}

then I don't get anything just blank output.

Is there a way to get the error page to display here with out doing a try catch inside the controller?

preguntado el 08 de noviembre de 11 a las 14:11

I don't think so. However, why should you get a 500 error in your controller? -

uncaught exception or syntax error. Sorry just though the controller is not throwing the exception its a service that the controller is using that throws the exception. -

Well, a working application shouldn't throw exceptions that are not caught or generate syntax errors, so I don't understand what you're trying to achieve here. If you see the controller's response is blank, have a look at the logs, find the problem and fix it. But you won't need it in a production environment. -

The other thing I just noticed is that the error log does not log the thrown exception if you render the controller inside the template. but it does get logged if you run the controller from the url ??? -

Está usted en dev ¿ambiente? -

1 Respuestas

When you use the render tag, you can specify some options as the third argument:

  • ignore_errors default FALSE in debug mode and TRUE otherwise
  • alt an alternative controller to execute in case of an error

The debug mode is activated by passing true as the value of the second kernel's constructor argument. You can see it in the front controller classes:

$kernel = new AppKernel('dev', true);

If you don't want to ignore errors, even in non-debug mode, you can do:

{% render 'BookingBundle:Booking:list' with {}, {'ignore_errors':false} %}

Respondido 09 ago 18, 21:08

brilliant thanks the "alt" sounds like what I want. I hate blank screens with no explanation. If I can run an alternative controller and just display a message that says "an error occurred" that would be brilliant and at the same time perhaps log something went wrong. Silently dying to the user is not my idea of fun, it can cause confusion (Not that my code will ever have bugs that will trigger this alt controller :) ). Thanks again - Alistair Prestidge

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.