Symfony 4 - ClassNotFoundException内核

时间:2017-12-26 18:17:35

标签: php symfony

我实际上将我的symfony 3.4项目升级到symfony 4.0。 在使用composer update从我的gitlab存储库中克隆束之后,我有一个错误:

ClassNotFoundException

Attempted to load class "Kernel" from namespace "App".
Did you forget a "use" statement for "Symfony\Component\HttpKernel\Kernel"?


in index.php (line 32)

好的....简单...去index.php第32行......但是,内核是用App \ Kernel加载的,所以任何想法为什么我有这个错误或我可以搜索的地方?

感谢您的帮助。

的index.php

use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;

require __DIR__.'/../vendor/autoload.php';

// The check is to ensure we don't use .env in production
if (!isset($_SERVER['APP_ENV'])) {
    (new Dotenv())->load(__DIR__.'/../.env');
}

if ($_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))) {
    umask(0000);

    Debug::enable();
}


    // Request::setTrustedProxies(['0.0.0.0/0'], Request::HEADER_FORWARDED);

$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev')));

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

在" src"目录,我有Kernel.php文件

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
    .....

2 个答案:

答案 0 :(得分:0)

Symfony 4使用文件夹“ App”自动加载“ psr-4”。我试图进行更改,但没有成功。在composer.json文件中的属性“ autoload”和“ psr-4”中检查名称空间。也许您更改了默认值。

答案 1 :(得分:0)

也许您不小心删除了{strong>始终需要 Symfony4的composer.json中的PSR-4块:

"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
},