从类对象中获取实体名称 [英] Get entity name from class object
本文介绍了从类对象中获取实体名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
namespace AcmeStoreBundleEntity;
use DoctrineORMMapping as ORM;
/**
* AcmeStoreBundleEntityUser
*
* @ORMTable(name="users")
* @ORMEntity()
*/
class User {
...
}
$user = new User();
有谁知道我现在如何从 User
对象获取实体名称 (AcmeStoreBundle:User
)?
Does anybody know how I can now get the entity name (AcmeStoreBundle:User
) from the User
object?
推荐答案
这应该总是有效的(不返回 Proxy 类):
This should always work (no return of Proxy class):
$em = $this->container->get('doctrine')->getEntityManager();
$className = $em->getClassMetadata(get_class($object))->getName();
由于 getClassMetadata
已被弃用,您现在可以使用 getMetadataFor
As getClassMetadata
is deprecated, you can now use getMetadataFor
$entityName = $this->em->getMetadataFactory()->getMetadataFor(get_class($object))->getName();
这篇关于从类对象中获取实体名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文