Symfony 3 bundle creation always throws "Edit the composer.json file"
Asked Answered
K

3

6

Hi I've been learning symfony, and every time I use the "php bin/console generate:bundle" command to create a bundle, even though I leave everything by default, I keep getting this error:

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:

I saw here in stackoverflow that this problem shows up when you try to put the bundle in a file different than src, but that's not the case, as I told you I leave everything by default; I mean I just enter the bundle name and then keep pressing enter until the proccess ends. Can anyone tell me what am I doing wrong? what's the cause? Thanks

Kremenchug answered 21/7, 2017 at 16:48 Comment(2)
Look at this answer https://mcmap.net/q/435234/-symfony3-classnotfoundexception-after-bundle-creation, the default behavior has been changed.Rework
So, you're saying that now it'll always give that error when creating a new bundle?Kremenchug
C
19

Edit composer.json:

Before:

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

After:

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

Then run:

composer dump-autoload 
Crellen answered 16/8, 2017 at 13:51 Comment(0)
P
24

Only change composer.json:

Before:

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

After:

"psr-4": {
            "": "src/"
        },

And finally, run:

composer dump-autoload
Paedogenesis answered 22/7, 2017 at 15:14 Comment(0)
C
19

Edit composer.json:

Before:

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

After:

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

Then run:

composer dump-autoload 
Crellen answered 16/8, 2017 at 13:51 Comment(0)
H
2

I had this problem in symfony 3.4.4 too.I use this role in composer.json And then the problem was fixed

befor

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

after

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

and then, cmd $ composer dump-autoload.

Hale answered 31/1, 2018 at 15:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.