gpt4 book ai didi

php - 无法通过 Composer 加载类

转载 作者:行者123 更新时间:2023-12-04 16:59:55 25 4
gpt4 key购买 nike

我尝试通过以下方式更新学说模式:

$ php bin/console doctrine:schema:update --force

我不断得到:
PHP Fatal error:  Uncaught 
Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to
load class "FOSUserBundle" from namespace "App\FOS\UserBundle".

内核.php:
 <?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}';

public function getCacheDir()
{
return $this->getProjectDir().'/var/cache/'.$this->environment;
}

public function getLogDir()
{
return $this->getProjectDir().'/var/log';
}

public function registerBundles()
{
$bundles = array(
new FOS\UserBundle\FOSUserBundle(),
);
$contents = require $this->getProjectDir().'/config/bundles.php';
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();
}
}
}

composer.json 文件:
"autoload": {
"psr-4": {
"App\\": "src/",
"FOS\\": "vendor/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "test/"
}

FOSUserBundle.php 命名空间是:
namespace FOS\UserBundle;

并且不工作,但 namaspace 应用程序工作正常。
我试过:
$ composer dump-autoload

我究竟做错了什么?在 FOS 之前,它仍然采用 App 命名空间。

最佳答案

您需要添加一个斜杠。

$bundles = array(
new \FOS\UserBundle\FOSUserBundle(),
);

关于php - 无法通过 Composer 加载类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49032851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com