【问题标题】:Symfony composer install - Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "SensioGeneratorBundle"Symfony 作曲家安装 - 未捕获 Symfony\Component\Debug\Exception\ClassNotFoundException:尝试加载类“SensioGeneratorBundle”
【发布时间】:2016-10-09 21:05:06
【问题描述】:

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();

欢迎任何建议:)

【问题讨论】:

标签: php composer-php symfony


【解决方案1】:

这也取决于你的目标:

  • 如果您想设置产品环境:运行 composer install --no-devSYMFONY_ENV=prod,错误应该会消失。

【讨论】:

    【解决方案2】:

    在我的情况下,Sensio Generator Bundle 在 Symfony 4 中已被弃用,因此您可以 评论或删除下面这 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();
        }
    

    【讨论】:

      【解决方案3】:

      在 Prod 环境中,未注册 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 环境中使用此捆绑包中的生成命令,您应该将声明从 dev 移动到 Prod(不推荐!)

      【讨论】:

      • 谢谢!这解决了我的问题
      • 我认为默认情况下正如@jeremy所说的那样对吗?
      【解决方案4】:

      这对我有用:

      $ cd project_folder
      $ composer dump-autoload
      

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

      【讨论】:

        猜你喜欢
        • 2019-04-27
        • 2019-08-02
        • 2020-05-15
        • 1970-01-01
        • 1970-01-01
        • 2020-01-21
        • 1970-01-01
        • 1970-01-01
        • 2018-08-18
        相关资源
        最近更新 更多