Для приложения я хотел бы создать пользовательскую страницу ошибки 404 в Symfony 4.
Но после того, как Symfony следовал документации, он вышел на всю страницу:
Invalid service "App\Controller\CustomExceptionController": class "App\Controller\CustomExceptionController" does not exist.
Я не знаю, почему он не может найти этот класс, пока у меня есть все плагины, необходимые для создания пользовательской страницы ошибок.
error404.html.twig
{% extends 'base.html.twig' %}
{% block main %}
<h1>Page not found</h1>
<p>
The requested page couldn't be located. Checkout for any URL
misspelling or <a href="{{ path('home') }}">return to the homepage</a>.
</p>
{% endblock %}
services.yaml
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'fr'
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
App\Controller\CustomExceptionController:
public: true
arguments:
$debug: '%kernel.debug%'
twig.yaml
twig:
default_path: '%kernel.project_dir%/templates'
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
exception_controller: App\Controller\ExceptionController::showException
страница ошибки