Reputation: 79
I specify that I am not a beginner with Symfony. It's not about creating a Controller, but an error I get when I try to create a Controller. I also specify that it is about an already existing website which comprise approximately 10 controllers.
To create a controller, I tried several methods:
symfony console make:controller NomController
Either way, I got the following error:
Expected to find class "App\Controller\NomController" in file "C:\wamp64\www\dev\nom-site\src\Controller\NomController.php" while importing services from resource "../src/", but it was not found! Check the namespace prefix used with the resource in C:\wamp64\www\dev\nom-site\src../config/services.yaml (which is being imported from "C:\wamp64\www\dev\nom-site\src\Kernel.php").
Obviously, the NomController
class exists in the NomController.php
file and:
Here is the services.yaml
file:
services:
_defaults:
autowire: true
autoconfigure: true
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Tests/'
I tested to add a new
I have exactly the same error. In fact, it is not a problem specific to controllers. It can be a modification so that symfony keeps in cache all the PHP classes (gain in performance).
Upvotes: 0
Views: 779
Reputation: 5713
There are multiple reasons that could cause this issue.
1. Check your class name and namespace (case sensitive)
In your case, your class name must be NomController
, namespace App\Controller\NomController
and located in src/Controller/NomController
2. Check for syntax errors
Weirdly enough, this error can pop up for other reasons such as a missing colon ;
3. Check your composer.json for your autoload config
With symfony default configuration, it should look like this:
{
"autoload": {
"psr-4": {"App\\": "src/"}
}
}
You can then run composer dump-autoload
to generate manually your vendor/autoload.php
file (used by your index.php).
Upvotes: 1