user3703456
user3703456

Reputation:

Symfony 3.3.5 - Can't generate new bundle

I've just installed new Symfony 3.3.5 project. Now I'm trying to generate new bundle

php bin/console generate:bundle

But getting this:

> Generating a sample bundle skeleton into app/../src/Web/BaseBundle
  created ./app/../src/Web/BaseBundle/
  created ./app/../src/Web/BaseBundle/WebBaseBundle.php
  created ./app/../src/Web/BaseBundle/Controller/
  created ./app/../src/Web/BaseBundle/Controller/DefaultController.php
  updated ./app/../tests/WebBaseBundle/Controller/DefaultControllerTest.php
  created ./app/../src/Web/BaseBundle/Resources/views/Default/
  created ./app/../src/Web/BaseBundle/Resources/views/Default/index.html.twig
  created ./app/../src/Web/BaseBundle/Resources/config/
  created ./app/../src/Web/BaseBundle/Resources/config/services.yml
  created ./app/../src/Web/BaseBundle/Resources/config/routing.yml
> Checking that the bundle is autoloaded
FAILED
> Enabling the bundle inside app/AppKernel.php
  updated ./app/AppKernel.php
OK

So fixed it in composer.json like this:

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

also tried like this:

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

But if I try to launch my project, I'm getting this error:

Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "WebBaseBundle" from namespace "Web\BaseBundle". Did you forget a "use" statement for another namespace? in /Volumes/U/Projects/e-shop/app/AppKernel.php on line 18

Here is my AppKernel

public function registerBundles()
{
    $bundles = [
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
        new Symfony\Bundle\MonologBundle\MonologBundle(),
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new Web\BaseBundle\WebBaseBundle(),
    ];

    if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
        $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
        $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();

        if ('dev' === $this->getEnvironment()) {
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
            $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
        }
    }

    return $bundles;
}

What can be possibly wrong in totally new project? Thanks for help.

Upvotes: 0

Views: 1004

Answers (1)

rapaelec
rapaelec

Reputation: 1330

to fix this bug you must edit composer.json :

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

and after run in command :

composer install (if composer is installed)

or 

php composer.phar (if you work with composer.phar)

Upvotes: 1

Related Questions