【问题标题】:Error in Appkernel Symfony2Appkernel Symfony2 中的错误
【发布时间】:2016-02-01 10:51:43
【问题描述】:

我一直收到同样的错误...我尝试过使用每个人的解决方案,但没有运气 错误:AppKernel.php 第 17 行中的 ClassNotFoundException: 试图从命名空间“AppBundle”加载类“AppBundle”。 您是否忘记了另一个命名空间的“使用”语句?

<?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 OC\PlatformBundle\OCPlatformBundle(),
        ];

        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();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

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

【问题讨论】:

  • 能否也分享一下您的 AppBundle 课程?还有你周围的目录结构!
  • 非常感谢我的问题解决了:)
  • 很高兴知道,您能否分享您的解决方案或在下面选择正确的解决方案?这对于帮助其他人并解决这个问题很重要

标签: symfony


【解决方案1】:

请检查您是否有目录AppBundle,如果不存在则从AppKernel.ph 文件中删除此行:

new AppBundle\AppBundle(),

【讨论】:

  • 多亏了你,现在一切都很好,非常感谢:)
  • 如果我回答了你的问题,请接受答案:)
【解决方案2】:

我认为您的 AppBundle 类没有(或错误地)定义。你应该有这个在src/AppBundle/AppBundle.php:

<?php

namespace AppBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AppBundle extends Bundle
{
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多