Symfony - Twig - Ovverride error page template - symfony

Following the lead of the cookbook:
http://symfony.com/doc/master/cookbook/controller/error_pages.html
The custom error pages are never rendered in production. If I understand correctly the problem is shared by many on the web. Does anyone know of a method that really works?

You can create custom exception listener which will for example render some template.
See the similiar post: Symfony2 Custom Error Exception Listener - Rendering templates or passing to a controller

Related

Symfony 4.1 dump doesn't work

I just installed the Symfony 4.1, the dump function doesn't work on controller but it works on twig files, if I remove the symfony/debug-bundle, then the dump works correctly in controller but it doesn't work in twig properly, it acts like simple var_dump.
Does any body have any idea why this is happening?
Symfony have new features for dump.
Now dump shown in symfony profiler.
Please check proper. In symfony profiler
This problem is fixed with symfony 4.1.1, https://github.com/symfony/symfony/releases/tag/v4.1.1
dd() in controller work after upgrate to 4.1.1 with composer "php composer update".
Just be careful, if you use dump in controller, then you should have WebProfilerBundle installed as well. Then you see output inside of that toolbar and not in page content.
I had the same problem just now and the other answers here were not relevant. If you look to the Profiler Bar, the "crosshairs(debug)" icon will show your dump from twig only (sometimes).
To see ALL dumps, you sometimes need to go track them down in the "Ajax Requests" part. To do this, click the Ajax Requests in the Symfony Profiler bar at the bottom of the screen. Then click the lines until you see a AJAX request that fired and has your dump.
The reason why only your Twig dump showed up is that the profiler bar is mostly about the primary request. The suppression is an ajax secondary request. The dump you asked about was in the ajax not the primary request.

How to disable fatal error in symfony

When my app couldn't connect to the database it throws a Fatal Error message :
so how to show a custom error page for this error like 404 page error ?
is there any configuration to do in symfony config.yml ?
thank you !
You can display custom 404, 403, 500 errors if you will override your default Twig-based template. For this purpose you should create folder "TwigBundle" in your app/Resources directory and emulate the following structure:
That should help. The mechanism is the same as for 404 page. This also can help you to extend my answer: Symfony documentation
You can also create Service and mark it as exception listener. In this service you can log your exception and display any response you like. You can actually do anything that can be done within Symfony Service.
More details:
Symfony documentation
My previous answer on this topic

How to force symfony2 to show nginx's default error pages

I'm using Symfony2.4, and my question is:
- Symfony always tries exception and shows its error page
- But if my web faces 500 error, I want it to show default error page of nginx.
Can anybody help me?
Thanks in advance!
The kernel is catching exception like 500, or 404...
By default, he call TwigBundle:Exception:show controller, that will choose the template to use.
Create this folder.
app/Resources/TwigBundle/views/Exception
And add twig templates with the same name as TwigBundle's templates. They will override the default template.

I'm getting fatal error after including SonataMediaBundle's form templates

I've configured SonataMediaBundle, added relation to Media in my Entity. Admin for entity works fine until I add this snippet from docs:
twig:
form:
resources:
# other files
- 'SonataMediaBundle:Form:media_widgets.html.twig'
After that all I get is this error:
FatalErrorException: Compile Error: Cannot inherit previously-inherited or override constant MARKER from interface Doctrine\Common\Persistence\Proxy
What I'm doing wrong? How to make sonata_media_type work with its widget template?
googling for somedays for a similar error I came up with the conclusion that is has nothing to do with your code, but is some kind of strange bug in environment, more likely in APC.
Check this post if you are using amazon server: https://forums.aws.amazon.com/message.jspa?messageID=508800
After I did that upgrade the problem solved. I'm still waiting to see if it comes out again, because it was not a permanet error, and after each apache reload/restart it went away for a while...
Other op-caches may solve the problem without loosing performance.

How does symfony2 inject the profiler?

When I use the dev AppKernel of my app symfony shows a profiler bar at the bottom of the site.
How does symphony does this? Does it transparently inject something into my templates? I ask this because when I output raw text with "return new Response" from a controller action no profiler code is appended.
Web profiler is injected during event kernel.response.
Precisely it's caused by WebDebugToolbarListener.php.
It checks if response content type is html and there's no xdebug token header.

Resources