Symfony EntityRepository return instance of “Proxies\__CG__ MyModelName”

后端 未结 2 1586
广开言路
广开言路 2021-02-20 06:37

Query

$em->getRepository($this->getRepositoryName(\'AppBundle:User\'))->find($id);

return object instance of Proxies\\__CG__\\A

2条回答
  •  梦谈多话
    2021-02-20 07:06

    Sometimes we need to respectively determine real class name for an Entity.

    Doctrine uses static methods, placed in a helper class: 'Doctrine\Common\Util\ClassUtils', for generating name of proxy class. Here is description: Class ClassUtils.

    In case you want to get a real class name, just use:

    $entityClassName = ClassUtils::getClass($entityObject);.

    I've found this useful for logging of entity data changes (original entity can be determined by id and class name).

    Hope it was helpfull.

提交回复
热议问题