Younes Oulkaid
Younes Oulkaid

Reputation: 65

How to display the 404 error page instead bugs in Symfony4

this my page : error404.html.twig as documentation Example 404 Error Template

{# templates/bundles/TwigBundle/Exception/error404.html.twig #} 
{% extends 'base.html.twig' %}
{% block body %}
<h1>Page not found</h1>
        <p>
            The requested page couldn't be located. Checkout for any URL
            misspelling or <a href="{{ path('homepage') }}">return to the homepage</a>.
        </p>

{% endblock %}

this my page config/routes/dev/twig.yaml

# config/routes/dev/twig.yaml
_errors:
    resource: '@TwigBundle/Resources/config/routing/errors.xml'
    prefix:   /_error

this my page config/packages/twig.yaml

# config/packages/twig.yaml
twig:
    exception_controller: App\Controller\ExceptionController::showException

what i should do to make it works?

the erreur is : : enter image description here

services.yaml : enter image description here

Upvotes: 4

Views: 15188

Answers (1)

Bananaapple
Bananaapple

Reputation: 3114

If you're in debug mode and instead of a 404 page you get a NotFoundHttpException then everything is fine in that this is the documented and desired behaviour, as described here: https://symfony.com/doc/current/controller/error_pages.html

In the development environment, Symfony catches all the exceptions and displays a special exception page

To bypass this and actually see your custom 404 page you need to access the template via a special route: http://localhost/index.php/_error/404

Upvotes: 6

Related Questions