PHP Symfony 试图从命名空间“Sonata\IntlBundle”加载类“SonataIntlBundle”[重复]

Posted

技术标签:

【中文标题】PHP Symfony 试图从命名空间“Sonata\\IntlBundle”加载类“SonataIntlBundle”[重复]【英文标题】:PHP Symfony Attempted to load class "SonataIntlBundle" from namespace "Sonata\IntlBundle" [duplicate]PHP Symfony 试图从命名空间“Sonata\IntlBundle”加载类“SonataIntlBundle”[重复] 【发布时间】:2020-05-30 07:32:19 【问题描述】:

我一般来说是 Symfony 和 php 的新手,我只想从 GitHub 建立一个项目,指令说我必须运行 composer update。因此,在此命令之后会出现错误日志:

 Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception

  [RuntimeException]                                                                                                                                                                                                               
  An error occurred when executing the "'cache:clear --no-warmup'" command:                                                                                                                                                        

  Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "SonataIntlBundle" from namespace "Sonata\IntlBundle".                                                                   
  Did you forget a "use" statement for another namespace? in /Users/xxx/Documents/project/app/AppKernel.php:28                                                                                                                 
  Stack trace:                                                                                                                                                                                                                     
  #0 /Users/xxx/Documents/project/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(427): AppKernel->registerBundles()                                                                                        
  #1 /Users/xxx/Documents/project/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(128): Symfony\Component\HttpKernel\Kernel->initializeBundles()                                                            
  #2 /Users/xxx/Documents/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(62): Symfony\Component\HttpKernel\Kernel->boot()                                                           
  #3 /Users/xxx/Documents/project/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(117): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Obj  
  ect(Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                                                                             
  #4 /U in /Users/xxx/Documents/project/app/AppKernel.php on line 28                                                                                                                                                           

  PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "SonataIntlBundle" from namespace "Sonata\IntlBundle".                                                              
  Did you forget a "use" statement for another namespace? in /Users/xxx/Documents/project/app/AppKernel.php:28                                                                                                                 
  Stack trace:                                                                                                                                                                                                                     
  #0 /Users/xxx/Documents/project/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(427): AppKernel->registerBundles()                                                                                        
  #1 /Users/xxx/Documents/project/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(128): Symfony\Component\HttpKernel\Kernel->initializeBundles()                                                            
  #2 /Users/xxx/Documents/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(62): Symfony\Component\HttpKernel\Kernel->boot()                                                           
  #3 /Users/xxx/Documents/project/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(117): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Obj  
  ect(Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                                                                             
  #4 /U in /Users/xxx/Documents/project/app/AppKernel.php on line 28       

谁能帮我解决这个问题?我有点迷路了。

【问题讨论】:

“我是 Symfony 和 PHP 的新手” 我最好的建议是停止使用任何框架,因为您是 PHP 新手。学习第一个普通 PHP,这将为您节省数百小时的调试时间。 @Cid 我只是想编辑前端层,反正不想用 PHP @Cid 没有帮助 考虑提供 github 项目的链接。看起来像一个旧项目,它可能没有正确指定依赖项。 @Cerad 很抱歉,我不允许这样做 【参考方案1】:

正如@Cid 提到的,我重新克隆了 repo,这次使用 composer install 而不是 update,它工作得很好!

【讨论】:

以上是关于PHP Symfony 试图从命名空间“Sonata\IntlBundle”加载类“SonataIntlBundle”[重复]的主要内容,如果未能解决你的问题,请参考以下文章

未捕获的 Symfony\Component\Debug\Exception\ClassNotFoundException:试图从命名空间“UserBundle\UserBundle”加载类“Use

试图从命名空间加载类“MyApp”

AppKernel.php 奇怪的东西

Symfony 自定义配置 - 命名空间问题

使用 Symfony 1.4 的自动加载器加载命名空间类?

Symfony 5.1.3 清除缓存时的问题:尝试从命名空间加载类“MappingDriverChain”