gpt4 book ai didi

php - Symfony2 - 获取实体名称

转载 作者:行者123 更新时间:2023-12-04 17:00:27 25 4
gpt4 key购买 nike

我使用此代码获取实体名称;

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

return $type;
}

但是,这个功能没有给我我想要的。这次回归;

Acme/DemoBundle/实体/用户

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

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

最佳答案

编辑:

尝试反射类:

$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;
}

关于php - Symfony2 - 获取实体名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22224688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com