404 route not found exception handling in symfony - php

I want to create a template for page not found. whenever 404 no route found exception is throwing need to redirect to page. As that is not in proper UI way. I tried steps from this URL
https://symfony.com/doc/current/controller/error_pages.html
I am new to symfony . followed steps until service.yml and created customExceptionController.php and I dont know what to do next step and I am getting error like
How to fix this issue.Please anyone help me to get out of this issue. Thanks in advance

In the dev environment, you will always see the default exception page which is meant to ease debugging issues. If you want to see how a certain error page looks like in the prod environment (because you maybe created a custom template for it), you need to access a special URL that is only available for this purpose in the dev enviromnent (see https://symfony.com/doc/current/controller/error_pages.html#testing-error-pages-during-development). In your case, this URL is http://127.0.0.1:8000/_error/404

Related

How to change default twig error templates in Symfony 4?

I am building an app using Symfony 4.4. I am trying to render custom 404 error page. I followed the documentation and created error.html.twig and error404.html.twig files in templates/bundles/TwigBundle/Exception. However I still get the 'Oops! An Error Occurred' with code 500 page that is by default from symfony.
Can someone point what can have I done wrong?
In dev mode I see that the app throws NotFoundHttpException but in prod mode I always get the page with code 500 even if I visit an undefined route.
This is what I get when I visit an undefiend route:
500 error
You can use the built-in Twig error renderer to override the default error templates. Both the TwigBundle and TwigBridge need to be installed for this
When the error page loads, Symfony\Bridge\Twig\ErrorRenderer\TwigErrorRenderer is used to render a Twig template to show the user.
This renderer uses the HTTP status code and the following logic to determine the template filename:
Look for a template for the given status code (like error500.html.twig);
If the previous template doesn’t exist, discard the status code and look for a generic error template (error.html.twig).
To override these templates, rely on the standard Symfony method for overriding templates that live inside a bundle and put them in the templates/bundles/TwigBundle/Exception/ directory.

Creating custom error page in Symfony 2.5

I am working with Symfony 2.5.3 and I am trying to create the custom error page so for example if someone lands on a page or try to access a page that does not exist the 404 error message should appear within the theme of the site.
I understand that default 404 error page sits inside the TwigBundle that comes with symfony and looking at some other answers on this site people are suggesting that in order to have the custom error page I need to copy them in directory ROOT app/Resources/TwigBundle/views/Exception so I copied over the error.html.twig and even created error404.html.twig but this does not work. I also looked into this solution but still no luck.
I tried to access my development site via http://127.0.0.1:8000/app.php/services to check may be in production i will see the correct template but I dont, please note that i have cleared the cache before accessing http://127.0.0.1:8000/app.php/services and I still see the default error template that comes with Symfony
I will really appreciate any help on this.
First double check this :
Check if you're custom error template is in app/Resources/TwigBundle/views/Exception folder
Then double check the name of you're custom error template if it is error.html.twig OR/AND error404.html.twig
Then create the custom error/template that you want users to see
You can see the custom error/page when you view the website via app.php which is a production environment.
Beetween each check
rm -rf app/cache/*
It should works now ;)
Another way to easily test your custom error template in dev mode is to use instead WebfactoryExceptionsBundle who provide a test controller for displaying your custom error page even when kernel.debug is set to true.

Phalclon route invo/index not found on server

I followed the tutorial at http://docs.phalconphp.com/en/latest/reference/tutorial-invo.html.
Everything wokrs fine but the "home" link, that points to localhost/invo/index/index/
will give an error stating file not found or what ever. Index is defined as it should be in the project and the funny thing is that if I type localhost/invo/foo/bar/(does not exist) I recive the message stating that I am not allowed to watch said module.
Am I missing something in the tutorial? Am I missing something? Or is this an apache problem? I get the same error when tying in /index in tutorial 1 aswell. So it seen that there is a bit problem just with the word "index".
Im running debian 7 by the way if thats somewhat relevant.
This is may not the full solution but apparently you have the same issue as the guy here http://forum.phalconphp.com/discussion/1393/indexcontroller-cause-unmanaged-404-error-on-apache-w-mod-rewrit
You may are right about the index for being special word as it is the default index page name, so you can avoid naming the controller as IndexController you can use something like HomeController.
Hint: try to clone the source code from git to ensure that you get the correct code with the correct .htaccss you may already did that.
git clone https://github.com/phalcon/invo.git

Zend framework URLs not working in local environment

I finally got a basic framework set up and working, however now when I wish to add an action in the 'IndexController.php', it doesn't seem to be working.
I used the following terminal command to add an "about" action:
zf create action about index
It appears that worked, as I opened 'IndexController.php' back up and the new action function is there. And a corresponding 'about.phtml' file was created in 'views/scripts/index', alongside 'index.phtml' that was already there.
When I access the index at
http://localhost3:8888/
the page opens properly.
However if I now try to access the about page at
http://localhost3:8888/index/about
I get a "404 not found" error.
Any ideas?
Looks like a mod_rewrite problem.
Try http://localhost3:8888/index.php/index/about. If it works, then it definitely means that mod_rewrite wasn't correctly set up.

Removing default routing in symfony causes internal server error

Error Message:
The route "default" does not exist.
Yes, it doesn't exist. But as described in the Doctrine version of "Practical Symfony | Day 5" everything should work well when default routing is removed, because all actions of the job module has been successfully routed by other routers.
I get the error when I request the URL below which is routed by a router other then the default one.
...jobeet.localhost/frontend_dev.php/job/sensio-labs/paris-france/1/web-developer
I'd be glad, if anyone would help me solving this issue. Thanks!
It sounds like you still have something referencing the 'default' route in your application or template code, maybe in a redirect, link_to or url_for function call. If you could post the first few lines of the stack trace I can be more specific.

Categories