Matoeil
Matoeil

Reputation: 7289

symfony2 bundle autoloading failed

I happen to get all the symfony problems of the creation...

I want to create a new project.

I copy the 'symfony2' folder, rename it then:

 php app/console generate:bundle

It says:

  Generating the bundle code: OK
  Checking that the bundle is autoloaded: FAILED
  Confirm automatic update of your Kernel [yes]? 
  Enabling the bundle inside the Kernel: OK
  Confirm automatic update of the Routing [yes]? 
  Importing the bundle routing resource: FAILED

  The command was not able to configure everything automatically.  
  You must do the following changes manually.                      

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

  Bundle MddevPsavBundle is already imported.

Why is this? When I did not have that problem last time I have done the same command?

How can I solve this exactly? and what shall I add exactly into that composer.json file ??

I have tried something but I get:

  Fatal error: Class 'Mddev\PsavBundle\MddevPsavBundle' not found in
  /var/www/projetQ/app/AppKernel.php on line 22

Upvotes: 2

Views: 16905

Answers (7)

GiorgosBarkos
GiorgosBarkos

Reputation: 79

Change composer.json in autoload

"autoload": {
            "psr-4": {
                "Composer\\CaBundle\\": "src"
            }
        },

add run the command composer dumpautoload

Upvotes: 0

juanitourquiza
juanitourquiza

Reputation: 2194

For fix this error is necesary add in composer.json this code:

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

Always that all Bundles are in /src This change was my solution in Symfony 3.3.x

Regards

Upvotes: 0

some_groceries
some_groceries

Reputation: 1192

when generating bundles form the command line the generator does not take into account the directory that the bundle is in, this might cause problems while adding vendor prefixes to your bundle, you need to make sure of two things for this to work

  1. check namespace in AppKernel.php > registerBundles()
  2. check namespace in the bundle's class
  3. run composer update just to make sure autoloader is created correctly

eg:- namespace Acme\UserBundle; in UserBundle.php

|-----|
|    src
|       |
|      Acme
|          |
|        UserBundle
|               .
|               .
|           UserBundle.php

And Inside AppKernel.php have new Acme\UserBundle\UserBundle(),

Upvotes: 0

user3625694
user3625694

Reputation: 51

I just had this exact problem. app/console generate:bundle was failing the autoload check and the src directory was not being created. I am so used to taking the default answers that I didn't notice that the src directory was pointing to the cache directory.

I typed in the proper path and all was well.

I guess familiarity really does breed contempt.

Upvotes: 2

Ved
Ved

Reputation: 73

I got the Error because I didn't have composer installed before running generate:bundle.

Once I installed composer, tried the command again (after deleting the files that bundle created and the code from app/AppKernal.php) it worked right away

Upvotes: 0

Andrew Atkinson
Andrew Atkinson

Reputation: 4251

If you are getting the problem:

The command was not able to configure everything automatically.  
You must do the following changes manually.

Which then tells you to:

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

Assuming you have followed the bundle name conventions correctly, then you will need to:


Add your new bundle to the composer.json file

"autoload": {
    "psr-0": {
        "currentbundle\\": "src/",
        "YOURNEWBUNDLE\\": "src/",            
    }
}

You then need to run install on composer again

composer -n install --dev

You should then have both of the bundles autoloaded

Upvotes: 10

Jakub Zalas
Jakub Zalas

Reputation: 36191

Seems that your bundle namespace doesn't follow conventions: http://symfony.com/doc/current/cookbook/bundles/best_practices.html#bundle-name

You should rather use Mddev\Bundle\MddevPsavBundle or Mddev\MddevPsavBundle as a bundle namespace.

Upvotes: 2

Related Questions