Med Karim Garali
Med Karim Garali

Reputation: 943

Symfony 3.4 : generate bundle : ClassNotFoundException: Attempted to load class "MyVendorFOSUserBundle" from namespace "MyVendorFOSUserBundle"

Hello every body I'm doing inheritance from FOSUserBundle to override some controllers, but At first step when I was creating a simple bundle I found an issue:

bin/console genrate:bundle

Are you planning on sharing this bundle across multiple applications? [no]:
Bundle name: MyVendorFOSUserBundle

Target Directory [src/]: src/MyVendor/

Configuration format (annotation, yml, xml, php) [annotation]: 

Bundle generation  

> Generating a sample bundle skeleton into app/../src/MyVendor/MyVendorFOSUserBundle
  created ./app/../src/MyVendor/MyVendorFOSUserBundle/
  created ./app/../src/MyVendor/MyVendorFOSUserBundle/MyVendorFOSUserBundle.php
  created ./app/../src/MyVendor/MyVendorFOSUserBundle/Controller/
  created ./app/../src/MyVendor/MyVendorFOSUserBundle/Controller/DefaultController.php
  created ./app/../tests/MyVendorFOSUserBundle/Controller/
  created ./app/../tests/MyVendorFOSUserBundle/Controller/DefaultControllerTest.php
  created ./app/../src/MyVendor/MyVendorFOSUserBundle/Resources/views/Default/
  created ./app/../src/MyVendor/MyVendorFOSUserBundle/Resources/views/Default/index.html.twig
  created ./app/../src/MyVendor/MyVendorFOSUserBundle/Resources/config/
  created ./app/../src/MyVendor/MyVendorFOSUserBundle/Resources/config/services.yml
> Checking that the bundle is autoloaded
FAILED
> Enabling the bundle inside app/AppKernel.php
  updated ./app/AppKernel.php
OK
> Importing the bundle's routes from the app/config/routing.yml file
  updated ./app/config/routing.yml
OK
> Importing the bundle's services.yml from the app/config/config.yml file
  updated ./app/config/config.yml
OK

  The command was not able to configure everything automatically.  
  You'll need to make the following changes manually.              

- Edit the composer.json file and register the bundle
  namespace in the "autoload" section:

At first solution I tried to modify composer.json :*

"autoload": {
    "psr-4": {
        "": "src/"  //modif 
    },
    "classmap": [
        "app/AppKernel.php",
        "app/AppCache.php"
    ]
},

Does someone have any idea about that

Upvotes: 0

Views: 1868

Answers (2)

Badri Bashipangu
Badri Bashipangu

Reputation: 11

  1. Open composer.json file.

  2. Change this:

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

    to:

    "autoload": { "psr-4": { "": "src/" },
    
  3. Run this command: composer dumpautoload Now composer will generate new autoload.php file

  4. Run command: php bin/console server:run everything works file.

Upvotes: 1

Med Karim Garali
Med Karim Garali

Reputation: 943

Finally, I found the solution:

"autoload": {
    "psr-4": {
        "AppBundle\\": "src/AppBundle",
        "MyVendorFOSUserBundle\\": "src/MyVendor/MyVendorFOSUserBundle" //Line added
    },
    "classmap": [
        "app/AppKernel.php",
        "app/AppCache.php"
    ]
},

Don't forget to run:

composer dumpautoload

Upvotes: 0

Related Questions