doukan4039 2017-09-13 13:48
浏览 66
已采纳

添加新捆绑包时出现Symfony3错误

I've a bundle that I created and is working in another project. I copied the Bundle folder inside the src folder, copied some segurity parameters, imported the service resource inside config.yml and add the bundle inside AppKernel.php as

new LoginBundle\LoginBundle()

And when I made a $ php bin/console doctrine:schema:validate it return this error

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "LoginBundle" from namespace "LoginBundle".
Did you forget a "use" statement for another namespace? in {project}\app\AppKernel.php:18
Stack trace:
#0 {project}\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(450): AppKernel->registerBundles()
#1 {project}\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(116): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 {project}\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php(69): Symfony\Component\HttpKernel\Kernel->boot()
#3 {project}\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php(125): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 {project}\bin\console(27): Symfo in {project}\app\AppKernel.php on line 18

EDIT

AppKernel.php content

<?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 LoginBundle\LoginBundle(),
            new AppBundle\AppBundle(),
        ];

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

And here goes the bundle file structure

bundle structure

Also this is the LoginBundle.php

namespace LoginBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class LoginBundle extends Bundle
{
}
  • 写回答

2条回答 默认 最新

  • dsbx40787736 2017-12-26 17:34
    关注

    My solution was generating aoutoloaders again like

    php composer.phar dump-autoload
    

    Hope it helps someone

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题