Symfony composer install - uncatch Symfony\Component\Debug\Exception\ClassNotFoundExcept



Composer无法在生产环境中安装symfony。开发过程中一切顺利。所有权限都可以。

PHP Fatal error:  Uncaught SymfonyComponentDebugExceptionClassNotFoundException: Attempted to load class "SensioGeneratorBundle" from namespace "SensioBundleGeneratorBundle".
Did you forget a "use" statement for another namespace? in /home/ev/app/AppKernel.php:25
Stack trace:
#0 /home/ev/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(396): AppKernel->registerBundles()
#1 /home/ev/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(114): SymfonyComponentHttpKernelKernel->initializeBundles()
#2 /home/ev/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(68): SymfonyComponentHttpKernelKernel->boot()
#3 /home/ev/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(118): SymfonyBundleFrameworkBundleConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#4 /home/ev/bin/console(27): SymfonyComponentConsoleApplication->run(Object(SymfonyComponentConsoleInp in /home/ev/app/AppKernel.php on line 25

这是AppKernel.php的第25行:

$bundles[] = new SensioBundleGeneratorBundleSensioGeneratorBundle();

欢迎任何建议:(

在Prod环境中,SensioGeneratorBundle未注册。这个捆绑包应该像开发捆绑包一样定义如下:

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

在您的作曲家文件中:

"require-dev": {
    "sensio/generator-bundle": "~2.3"
}

如果您想在Prod-env中使用此捆绑包中的生成命令,您应该将声明从dev移动到Prod(不推荐!(

这也取决于您的目标:

  • 如果你想设置一个prod-env:运行composer install --no-devSYMFONY_ENV=prod,错误就会消失

在我的案例中,Sensio Generator Bundle在Symfony 4中被弃用,因此您可以评论或删除下面的2行。

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

这对我有效:

$ cd project_folder
$ composer dump-autoload

这将重新加载文件并加载您的设置。

相关内容

  • 没有找到相关文章

最新更新