【问题标题】:The annotation "@Doctrine\ORM\Mapping\Entity" in class does not exist, or could not be auto-loaded.类中的注释“@Doctrine\ORM\Mapping\Entity”不存在,或者无法自动加载。
【发布时间】:2018-09-22 23:16:05
【问题描述】:

我遇到了一个众所周知的 Doctrine 错误,但似乎没有任何效果。

[语义错误] 中的注释“@Doctrine\ORM\Mapping\Entity” ac\User\Entity\User 类不存在,或无法自动加载。

我的课是这样开始的:

<?php
namespace ac\User\Entity;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class User

我的cli-config.php

<?php

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

require_once "vendor/autoload.php";

$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src/Entity"), $isDevMode);

// database configuration parameters
$conn = array(

    'driver' => 'pdo_mysql',
);

// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);

return ConsoleRunner::createHelperSet($entityManager);

关于这个问题肯定有 100 个问题。教义确实需要就此达成共识。

【问题讨论】:

    标签: doctrine-orm


    【解决方案1】:

    你的 symfony 版本是多少?

    如果您使用 symfony 4,我建议您安装这些依赖项:

    composer require symfony/orm-pack symfony/maker-bundle sensio/framework-extra-bundle
    

    sensio/framework-extra-bundle 似乎是使用实体或表格等学说注释所必需的。

    【讨论】:

    • 这是我的教义版本。我设置了“最低稳定性”:“dev”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 2022-10-26
    • 2017-03-06
    • 2018-07-11
    相关资源
    最近更新 更多