致命错误:AppKernel.php中找不到类

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了致命错误:AppKernel.php中找不到类脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我在Symfony文档之后生成一个新的Bundle(imgBundle),但是当在浏览器中重新加载应用程序时,它无法识别该bundle的主类.

这是我的ImgBundle.PHP

<?PHP

namespace ImgBundle;

use Symfony\component\HttpKernel\Bundle\Bundle;

class ImgBundle extends Bundle
{
}

AppKernel.PHP

<?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 ImgBundle\ImgBundle(),];

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

}

这是错误

提前致谢

解决方法

你需要改变你的composer.json我觉得用这样的psr-4自动加载:

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

需要在控制台内启动后:

composer dump-autoload

脚本宝典总结

以上是脚本宝典为你收集整理的致命错误:AppKernel.php中找不到类全部内容,希望文章能够帮你解决致命错误:AppKernel.php中找不到类所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。