Php Symfony2-获取实体名称

Php Symfony2-获取实体名称,php,symfony,namespaces,entity,Php,Symfony,Namespaces,Entity,Im使用此代码获取实体名称 function setTypeFunction($data) { $em = $this->container->get('doctrine')->getManager(); $type = $em->getClassMetadata(get_class($data))->getName(); return $type; } 但是,这个函数并没有给出我想要的。这种回归

Im使用此代码获取实体名称

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

        return $type;
    }
但是,这个函数并没有给出我想要的。这种回归

Acme/DemoBundle/Entity/User

但是,我只想要实体名称;所以“用户”

我该怎么办?我不想使用strstrip等功能。

编辑:

尝试ReflectionClass:

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

为什么不想使用函数

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

因为这不是唯一的方法。我找到了它$type=new\ReflectionClass($data)$type=$type->getShortName();谢谢你的帮助!是的,同时!