简体   繁体   English

Symfony3:致命错误:在 .\\bin\\console 中找不到“AppKernel”类

[英]Symfony3: Fatal error: Class 'AppKernel' not found in .\bin\console

just started working on a project, I ran composer update and was greeted with a exception when trying to clear cache.刚刚开始从事一个项目,我运行了composer update并在尝试清除缓存时遇到了异常。

When I try to run php bin\\console server:run I am greeted with this message:当我尝试运行php bin\\console server:run我收到了这条消息:

php bin\console server:run
PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Fatal error: Class 'AppKernel' not found in CoreBundle\bin\console:27
Stack trace:
#0 {main}
  thrown in CoreBundle\bin\console on line 27

Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Fatal error: Class 'AppKernel' not found in CoreBundle\bin\console on line 27

Symfony\Component\Debug\Exception\FatalThrowableError: Fatal error: Class 'AppKernel' not found in CoreBundle\bin\console on line 27

Call Stack:
    0.0112     427536   1. Symfony\Component\Debug\ErrorHandler->handleException() CoreBundle\vendor\symfony\symfony\src\Symfony\Component\Debug\ErrorHandler.php:0

Another strong possibility, particularly if the project has been updated from a v2.7 project (or before) is that the AppKernel is just not known to Composer.另一个很大的可能性,特别是如果项目是从 v2.7 项目(或之前)更新的,则 Composer 不知道 AppKernel。 It is now best practice to not manually require/include the file, (so those lines are removed from web/app_*.php , and bin/console.php ).现在最好的做法是不要手动要求/包含文件,(因此这些行从web/app_*.phpbin/console.php中删除)。 but instead have it autoloaded.而是让它自动加载。 However, this requires a line in Composer so that it can be found.但是,这需要 Composer 中的一行才能找到。 Only the composer autoloader would ever be included manually, which can then load everything else.只有 Composer 自动加载器会被手动包含,然后它可以加载其他所有内容。

"autoload": {
    "files": ["app/AppKernel.php"],
    "psr-4": {  // etc...

There are two possible reasons for this.这有两个可能的原因。

First your autoloader is trashed or can't find files首先,您的自动加载器已损坏或找不到文件

composer dump-autoload

Second reason could be, that your var directory isn't writable in which the cache file for symfony is placed.第二个原因可能是,您的var目录不可写,symfony 的缓存文件位于其中。 Just check the permissions.只需检查权限。 Also take a close look into the log files.还要仔细查看日志文件。 Maybe it tells you what the real Problem is.也许它会告诉你真正的问题是什么。 (Like an issue with syntax etc.) (比如语法问题等)

For some reason, I had to explicitly add src/Kernel.php to autoload.出于某种原因,我必须明确地将src/Kernel.php添加到自动加载。 So my composer.json autoload section became:所以我的 composer.json 自动加载部分变成了:

"autoload" : {
        "files": ["app/AppKernel.php",
                  "src/Kernel.php"],
        "psr-4": { "": "src/"},
      "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
    ]
        }

After adding this, running composer dump-autoload did the trick.添加此内容后,运行composer dump-autoload

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM