从存储库获取时,Doctrine如何在不调用__construct方法的情况下创建实体? [英] How Doctrine create an entity without call __construct method when fetch from repository?

查看:73
本文介绍了从存储库获取时,Doctrine如何在不调用__construct方法的情况下创建实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在构造函数中编写了下一个代码:

 公共函数__construct()
{
die( 创建实体);
}

当我使用 new创建实体的实例时运算子,例如:

  $ entity = new Entity(); 

我看到创建实体文本。 / p>

但是当我从回购中获取实体时:

  $ em-> ; getRepository('AcmeDemoBundle:Entity')-> find(1)

Doctrine创建一个对象实体而未调用 __ construct()方法,并且看不到正在创建实体文本。



有人可以解释从存储库中加载时,Doctrine如何创建对象吗?

解决方案

要创建没有调用构造器的实例,该构造器可用于 ReflectionClass :: newInstanceWithoutConstructor



Doctrine在文档\ORM\映射\ClassMetadataInfo :: newInstance()


I wrote next code in constructor:

public function __construct()
{
    die('creating entity');
}

When I create instance of entity with new operator like:

$entity = new Entity();

I see the creating entity text.

But when I get entity from repo:

$em->getRepository('AcmeDemoBundle:Entity')->find(1)

Doctrine create an object of entity without calling __construct() method and I don't see the creating entity text.

Can anybody explain how Doctrine creating an object when loading them from repository?

解决方案

To create an instance without invoking constructor available with ReflectionClass::newInstanceWithoutConstructor

Doctrine create instances of mapped entities without invoking constructor in Doctrine\ORM\Mapping\ClassMetadataInfo::newInstance()

这篇关于从存储库获取时,Doctrine如何在不调用__construct方法的情况下创建实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆