致命错误:AppKernel.php中找不到类
发布时间:2020-12-13 22:21:24 所属栏目:PHP教程 来源:网络整理
导读:我在Symfony文档之后生成了一个新的Bundle(ImgBundle),但是当在浏览器中重新加载应用程序时,它无法识别该bundle的主类. 这是我的ImgBundle.php: ?phpnamespace ImgBundle;use SymfonyComponentHttpKernelBundleBundle;class ImgBundle extends Bundle{}
我在Symfony文档之后生成了一个新的Bundle(ImgBundle),但是当在浏览器中重新加载应用程序时,它无法识别该bundle的主类.
这是我的ImgBundle.php: <?php namespace ImgBundle; use SymfonyComponentHttpKernelBundleBundle; class ImgBundle extends Bundle { } 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 AppBundleAppBundle(),new ImgBundleImgBundle(),]; 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'); } } 这是错误: 提前致谢 解决方法
你需要改变你的composer.json我觉得用这样的psr-4自动加载:
"autoload": { "psr-4": { "": "src/" },"classmap": [ "app/AppKernel.php","app/AppCache.php" ] } 需要在控制台内启动后: composer dump-autoload (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |