无法通过 Composer 加载 class
Failed to load class via Composer
我尝试通过以下方式更新学说架构:
$ 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".
Kernel.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 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".
Kernel.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(),
);