D
D
Daniel2021-05-11 18:00:35
symfony
Daniel, 2021-05-11 18:00:35

Why an error when creating a new route?

There is a project that needs to be changed. When creating a new controller, according to the existing namespace, the following error occurs

Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: Expected to find class "App\Controller\MyController" in file "/var/www/app/src/Controller/MyController.php" while importing services from resource ". ./src/*", but it was not found! Check the namespace prefix used with the resource.

I have already checked everything several times and still the

UPD error.
MyController.php
does not see, but
TestController.php
sees (the contents of the files are the same except for the names of the classes corresponding to the names of the files).

UPD 2. SOLUTION

found a solution and it is painfully strange.
I created controllers all by hand (I wrote the names of files and classes myself, not copy-paste). One controller accepts, the other does not.

At random, I found out that when creating a controller that it accepts, you need to run any route, if there is a cache error, then run it again.
Then I change the name of the file and class. I launch any route.
I add one method at a time and after each I start the route ...

All other changes are made using this method.
He swore only at controllers and services, he accepted entities and repositories right away.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sl0, 2021-05-11
@daniil46

/var/www/app/src/Controller(/)MyController.php
It looks like the slash was forgotten in the settings.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question