【问题标题】:MappingException with Doctrine ORM - Class does not exist带有 Doctrine ORM 的 MappingException - 类不存在
【发布时间】:2019-11-10 08:48:11
【问题描述】:

我在我的 PHP 项目中使用 Doctrine 2.6.2。 Schema 已使用 ORM-Tool 成功创建,但在运行时,会引发 MappingException。

我仍然无法理解异常错误消息“类'凭据'不存在于...”,因为我不了解教义内部。

我的 composer.json 文件:

{
    "require": {
        "doctrine/orm": "^2.6.2",
        "symfony/yaml": "2.*"
    },
    "autoload": {
        "psr-0": {"": "src/"}
    }
}

我尝试更改一些 phpdoc 注释并多次重置架构。

有人遇到过类似的教义问题吗?我很喜欢这个提示,因为我什至不确定这个问题是由我的 PHP 代码文件引起的,还是由我正在使用的 orm 工具的一些错误配置引起的,或者很可能是由我没想到的东西引起的还没有。

/**
 * @Entity @Table(name="credentials")
 */
class Credentials
{

    /** @Id @Column(type="integer") @GeneratedValue **/
    protected $id;

    /** @Column(type="string") **/
    public $Email;

    /** @Column(type="string") **/
    public $Loginname;

    /** @Column(type="string") **/
    public $EntropyString;

    /** @Column(type="string") **/
    public $AccessToken;


    public function __construct()
    {

    }

    public function getId()
    {
        return $this->id;
    }

}

这是来自 apache 的完整回复:

致命错误:未捕获 Doctrine\Common\Persistence\Mapping\MappingException: 类 “凭据”不存在于 F:\XAMPP\httpd.private\src\php\vendor\doctrine\persistence\lib\Doctrine\Common\Persistence\Mapping\MappingException.php:93 堆栈跟踪:#0 F:\XAMPP\httpd.private\src\php\vendor\doctrine\persistence\lib\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php(24): Doctrine\Common\Persistence\Mapping\MappingException::nonExistingClass('credentials')

1 F:\XAMPP\httpd.private\src\php\vendor\doctrine\persistence\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(250):

Doctrine\Common\Persistence\Mapping\RuntimeReflectionService->getParentClasses('credentials')

2 F:\XAMPP\httpd.private\src\php\vendor\doctrine\persistence\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(283):

Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getParentClasses('credentials')

3 F:\XAMPP\httpd.private\src\php\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\ClassMetadat

在 F:\XAMPP\httpd.private\src\php\vendor\doctrine\persistence\lib\Doctrine\Common\Persistence\Mapping\MappingException.php 在第 93 行

在调用 EntityManager 的 Find 方法时发生错误:

$this->credentials = $this->entityManager->Find('credentials', $result[0]["id"]);

【问题讨论】:

  • 你能显示你的类被声明的文件名吗?
  • 文件名为“credentials.php”
  • 使用 upletter - Credentials.php :)
  • 我在将文件名更改为“Credentials.php”后再次尝试。 -> 相同的 MappingException。
  • 你使用一些框架吗?

标签: php orm doctrine


【解决方案1】:

将完全限定的类名添加到对 EntityManager 的 Find 方法的调用后,该异常不再发生:

$this->credentials = $this->entityManager->Find('Businessrelations\Database\Credentials', $result[0]["id"]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 2017-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多