Composer无法在生产环境中安装symfony。一切都在开发中运作良好。所有权限都没问题。
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "SensioGeneratorBundle" from namespace "Sensio\Bundle\GeneratorBundle".
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): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 /home/ev/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(68): Symfony\Component\HttpKernel\Kernel->boot()
#3 /home/ev/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(118): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /home/ev/bin/console(27): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Inp in /home/ev/app/AppKernel.php on line 25
这是AppKernel.php的第25行:
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
欢迎任何建议:)
答案 0 :(得分:7)
在Prod environnment中,不会注册SensioGeneratorBundle。 应该将此包定义为开发包,如下所示:
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
在作曲家文件中:
"require-dev": {
"sensio/generator-bundle": "~2.3"
}
如果你想在Prod env中使用这个包中的生成命令,你应该将声明从dev移到Prod(不推荐!)
答案 1 :(得分:0)
这也取决于您的目标:
composer install --no-dev
和SYMFONY_ENV=prod
,错误应消失。答案 2 :(得分:0)
这对我有用:
$ cd project_folder
$ composer dump-autoload
这将重新加载文件并加载您的设置。
答案 3 :(得分:0)
就我而言,Symfony 4 中不推荐使用 Sensio Generator Bundle,因此您可以 评论或删除下面的 2 行。
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
//$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
//$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
答案 4 :(得分:-1)
在 Symfony 3.x 中,您只需在AppKernel.php
中对此行进行评论:
if ('dev' === $this->getEnvironment()) {
// Comment This line $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}