eZ Platform Discussions

I just want to generate a bundle


#1

I am just trying to generate a bundle with the dedicated command …
But, something goes wrong with the autoloaded.

root@my:/var/www/my/ezplatform # php app/console generate:bundle

Bundle name []: InitialImportBundle
Target Directory [src/]:

Generating a sample bundle skeleton into app/…/src/InitialImportBundle
created ./app/…/src/InitialImportBundle/
created ./app/…/src/InitialImportBundle/InitialImportBundle.php
created ./app/…/src/InitialImportBundle/Controller/
created ./app/…/src/InitialImportBundle/Controller/DefaultController.php
updated ./app/…/tests/InitialImportBundle/Controller/DefaultControllerTest.php
created ./app/…/src/InitialImportBundle/Resources/views/Default/
created ./app/…/src/InitialImportBundle/Resources/views/Default/index.html.twig
created ./app/…/src/InitialImportBundle/Resources/config/
created ./app/…/src/InitialImportBundle/Resources/config/services.yml
created ./app/…/src/InitialImportBundle/Resources/config/routing.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:

My composer.json look like that :

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

I modify it as well

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

But that’s not enough.
rm -rf app/cache/* && php app/console cache:clear --env=dev

Do not run Composer as root/super user! See https://getcomposer.org/root for details
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class “InitialImportBundle” from namespace “InitialImportBundle”.
Did you forget a “use” statement for another namespace? in /var/www/my/ezplatform/app/AppKernel.php:50

I also tried with:

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

And with others vary. But nothing works.
What do I miss?


#2

try

composer dump-autoload


#3

Thanks dude !

I do not understand how the rest of the site could work without it.
Or why I no longer need to run it when I create new bundles.
But I put this in my list of commands to execute to solve these many problems that I do not understand …


#4

There are some changes coming with symfony3. I will recommend when you start working with bundles , then add below code to your autoload to avoid any conflict. The composer dump-autoload will not be later required.

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

Of course, you could add the bundle namespace and path to the autolaod before creating any bundle or creating the bundle and then execute the above command.