简体   繁体   English

Symfony2 - 获取实体名称

[英]Symfony2 - Get Entity Name

Im use this code for getting entity name; 我使用此代码获取实体名称;

function setTypeFunction($data)
    {
        $em = $this->container->get('doctrine')->getManager();
        $type = $em->getClassMetadata(get_class($data))->getName();

        return $type;
    }

but, this function not give me i want. 但是,这个功能不给我我想要的。 this returning; 这回归;

Acme/DemoBundle/Entity/User ACME / DemoBundle /实体/用户

but, i want just entity name; 但是,我只想要实体名称; so "User". 所以“用户”。

What should i do? 我该怎么办? I dont wanna use strstrip etc. function. 我不想使用strstrip等功能。

Edit: 编辑:

Try ReflectionClass: 试试ReflectionClass:

$ref = new ReflectionClass($data);
$ref->getShortName()

why don't want to use function? 为什么不想使用功能?

function setTypeFunction($data)
{
    $em = $this->container->get('doctrine')->getManager();
    $type = $em->getClassMetadata(get_class($data))->getName();
    $type = end(explode("/",$type));
    return $type;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM