Following the example in the documentation:
https://symfony.com/doc/current/page_creation.html
I run into this error message:
The autoloader expected class "App\Controller\LuckyController" to be defined in file "/var/www/my-project/vendor/composer/../.. /src/Controller/LuckyController.php". The file was found but the class was not in it, the class name or namespace probably has a typo in /var/www/my-project/config/services.yaml (which is loaded in resource "/var/www/my-project/config/services.yaml").
In the "src/Controller/LuckyController.php", I have:
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
class LuckyController {
public function number() {
$number = mt_rand(0, 100);
return new Response('<html><body>Lucky number: '.$number.'</body></html>');
}
}
In the service.yml, I have:
parameters:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
App\:
resource: '../src/*'
exclude: '../src/{Entity,Migrations,Tests}'
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
I am not sure why the class "App\Controller\LuckyController" cannot be found. I wonder if anyone can help. Many thanks!