找不到类别'Doctrine \ Common \ Annotations \ AnnotationRegistry'

时间:2018-11-06 01:53:19

标签: php doctrine-orm doctrine

我第一次使用Doctrine,但遇到了一个错误。我在前一天晚上离开了项目,这个错误不存在,在新机器上启动了Web服务器,并对此表示欢迎。

  

致命错误:未捕获错误:类   在以下位置找不到“ Doctrine \ Common \ Annotations \ AnnotationRegistry”   D:\ website \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ Configuration.php:156   堆栈跟踪:#0   D:\ website \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ Tools \ Setup.php(72):   Doctrine \ ORM \ Configuration-> newDefaultAnnotationDriver(Array,true)#1   D:\ website \ src \ setup.php(16):   原则\ ORM \ Tools \ Setup :: createAnnotationMetadataConfiguration(Array,   true)#2 D:\ website \ src \ bootstrap.php(6):   include('C:\ Users \ admin \ ...')#3 D:\ website \ public \ index.php(7):   require('C:\ Users \ admin \ ...')#4 {main}被抛出   D:\ website \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ Configuration.php在   156行

我尝试过composer updatecomposer install,但都没有帮助。

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

$paths = array(ROOT . "/src/Database/Modals");
$config = $container->get('App\Providers\Config');

$dbParams = array(
    'driver'   => $config->get('database.driver'),
    'user'     => $config->get('database.user'),
    'password' => $config->get('database.password'),
    'dbname'   => $config->get('database.name'),
);

$entityConfig = Setup::createAnnotationMetadataConfiguration($paths, true);
$entityManager = EntityManager::create($dbParams, $entityConfig);

这行代码似乎抛出了异常。

$entityConfig = Setup::createAnnotationMetadataConfiguration($paths, true);

2 个答案:

答案 0 :(得分:0)

1)使用ssh连接服务器。

2)找到脚本工作的路径。

3)运行composer require doctrine/annotations

4)您可以在FTP中找到供应商目录

5)向您的代码声明一个要求。像require_once 'vendor/autoload.php'

让我知道是否有帮助。

答案 1 :(得分:0)

@ martin-barker的上述评论对我有用:

composer require doctrine/annotations