【问题标题】:Symfony - 无法找到自定义内核命名空间
【发布时间】:2022-01-22 12:16:37
【问题描述】:

我在 Symfony 中更改了目录结构,我希望它能够正常工作。

自动加载:

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

前端控制器(public\index.php):

<?php

declare(strict_types=1);

use D2D\Shared\Infrastructure\SymfonyKernel;
use Symfony\Component\HttpFoundation\Request;

require dirname(__DIR__).'/vendor/autoload.php';

$kernel = new SymfonyKernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

内核(src\Shared\Infrastructure\SymfonyKernel.php):

<?php

namespace D2D\Shared\Infrastructure;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

class SymfonyKernel extends BaseKernel
{
    use MicroKernelTrait;

    ... everything else as default
}

我得到的错误:

尝试从命名空间“App”加载类“Kernel”。你忘了吗 “Symfony\Component\HttpKernel\Kernel”的“使用”语句?

【问题讨论】:

    标签: symfony symfony-kernel


    【解决方案1】:

    我忘记了 cli 命令正在通过 bin/console,所以我不得不在那里更改 SymfonyKernel 的命名空间,因为它是创建内核的单独环境。

    【讨论】:

      猜你喜欢
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      • 2015-09-15
      • 2015-02-02
      • 1970-01-01
      • 1970-01-01
      • 2016-07-06
      相关资源
      最近更新 更多