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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了添加新捆绑包时出现Symfony3错误相关的知识,希望对你有一定的参考价值。

我创建了一个捆绑包并且正在另一个项目中工作。我复制了src文件夹中的Bundle文件夹,复制了一些segurity参数,在config.yml中导入了服务资源,并在AppKernel.php中添加了bundle作为

新的LoginBundle LoginBundle()

当我做了一个$ php bin/console doctrine:schema:validate它返回这个错误

PHP Fatal error:  Uncaught SymfonyComponentDebugExceptionClassNotFoundException: Attempted to load class "LoginBundle" from namespace "LoginBundle".
Did you forget a "use" statement for another namespace? in {project}appAppKernel.php:18
Stack trace:
#0 {project}vendorsymfonysymfonysrcSymfonyComponentHttpKernelKernel.php(450): AppKernel->registerBundles()
#1 {project}vendorsymfonysymfonysrcSymfonyComponentHttpKernelKernel.php(116): SymfonyComponentHttpKernelKernel->initializeBundles()
#2 {project}vendorsymfonysymfonysrcSymfonyBundleFrameworkBundleConsoleApplication.php(69): SymfonyComponentHttpKernelKernel->boot()
#3 {project}vendorsymfonysymfonysrcSymfonyComponentConsoleApplication.php(125): SymfonyBundleFrameworkBundleConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#4 {project}inconsole(27): Symfo in {project}appAppKernel.php on line 18

编辑

AppKernel.php内容

<?php

use SymfonyComponentHttpKernelKernel;
use SymfonyComponentConfigLoaderLoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            new SymfonyBundleFrameworkBundleFrameworkBundle(),
            new SymfonyBundleSecurityBundleSecurityBundle(),
            new SymfonyBundleTwigBundleTwigBundle(),
            new SymfonyBundleMonologBundleMonologBundle(),
            new SymfonyBundleSwiftmailerBundleSwiftmailerBundle(),
            new DoctrineBundleDoctrineBundleDoctrineBundle(),
            new SensioBundleFrameworkExtraBundleSensioFrameworkExtraBundle(),
            new LoginBundleLoginBundle(),
            new AppBundleAppBundle(),
        ];

        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            $bundles[] = new SymfonyBundleDebugBundleDebugBundle();
            $bundles[] = new SymfonyBundleWebProfilerBundleWebProfilerBundle();
            $bundles[] = new SensioBundleDistributionBundleSensioDistributionBundle();

            if ('dev' === $this->getEnvironment()) {
                $bundles[] = new SensioBundleGeneratorBundleSensioGeneratorBundle();
                $bundles[] = new SymfonyBundleWebServerBundleWebServerBundle();
            }
        }

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

这里是捆绑文件结构

bundle structure

这也是LoginBundle.php

namespace LoginBundle;

use SymfonyComponentHttpKernelBundleBundle;

class LoginBundle extends Bundle
{
}
答案

我的解决方案是再次生成自动加载器

php composer.phar dump-autoload

希望它可以帮助某人

另一答案

我想在routing.yml你必须添加

login:
    resource: "@LoginBundle/Controller/"
    type:     annotation
    prefix:   /

以上是关于添加新捆绑包时出现Symfony3错误的主要内容,如果未能解决你的问题,请参考以下文章

应用程序启动时出现错误“无法获取 BatchedBridge,请确保您的捆绑包已正确打包”

Symfony3 / Doctrine2 中 $em->clear() 时出现未定义索引错误

Behat 与 Symfony3 不兼容?

登录 Facebook 时出现 com.facebook.sdk 错误 2

捆绑标识符不能从以前的版本更改

错误3004:从行开始映射片段时出现问题