0
votes

During configuration my symfony app I've got an error about wrong namespaces for my controllers, but I'm sure that file exist in the path which was displaying in the error message and my configuration seems to be correct

Expected to find class "App\Controller\AccountController" in file "/var/www/html/src/App/Controller/AccountController.php" while importing services from resource "../src/App/*", but it was not found! Check the namespace prefix used with the resource in /var/www/html/config/services.yaml (which is loaded in resource "/var/www/html/config/services.yaml").

/var/www/html/config/services.yaml file

services:
    _defaults:
        autowire: true
        autoconfigure: true

    App\:
        resource: '../src/App/*'
        exclude: '../src/App/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    App\Controller\:
        resource: '../src/App/Controller'
        tags: ['controller.service_arguments']

composer.json

"autoload": {
        "psr-4": {
            "App\\": "src/App/",
            "": "src/"
        }
    }

Folder structure

/src:
    /App:
        /Controller:
            AccountController.php

controller namespace

namespace App\Controller;

1

1 Answers

-1
votes

It seems you are using psr-0 style autoloader, not psr-4.

You have to edit your composer.json like:

{
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    }
}

and move your Controller directory directly into src

or

you can set this into your composer.json

{
    "autoload": {
        "psr-0": {
            "App\\": ["src/"]
        }
    }
}