Symfony 3 ClassNotFoundException when creating Bundle

2

So far I had used Symfony 2 and I just moved to version 3. The installation is correct and I can run the emulator and see the welcome screen. The problem is when creating a Bundle. I create the bundle as always, with console and following the instructions and my bundle is created; but ... everything is over I can not do anything anymore, I can not run the server, create a database, entity, I always get the following error:

  

(1/1) ClassNotFoundException

     

Attempted to load class "ServicesBundle" from namespace   "ServicesBundle".

     

Did you forget to "use" statement for another namespace?

     

in AppKernel.php (line 19)

     

at AppKernel-> registerBundles () in Kernel.php (line 450)

     

at Kernel-> initializeBundles () in Kernel.php (line 116)

     

at Kernel-> boot () in Kernel.php (line 168)

     

at Kernel-> handle (object (Request)) in app_dev.php (line 29)

The AppKernel.php file

    <?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    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 AppBundle\AppBundle(),
            new ServiciosBundle\ServiciosBundle(),
        ];

        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;
    }

    public function getRootDir()
    {
        return __DIR__;
    }

    public function getCacheDir()
    {
        return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
    }

    public function getLogDir()
    {
        return dirname(__DIR__).'/var/logs';
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
    }
}

The ServicesBundle.php file

<?php

namespace ServiciosBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class ServiciosBundle extends Bundle
{
}

Thank you very much

    
asked by Josue 10.07.2017 в 01:04
source

1 answer

1
  • Edit composer.json and leave the field psr-4 as it was initially:

    "psr-4": { "": "src/" },
    
  • Launch the following command from the project directory:

    composer dump-autoload
    
  • Edit composer.json and re-add the information you had in:

    psr-4
    
  • answered by 29.08.2017 в 12:12