I have the following code:
namespace Acme\StoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Acme\StoreBundle\Entity\User
*
* @ORM\Table(name="users")
* @ORM\Entity()
*/
class User {
...
}
$user = new User();
Does anybody know how I can now get the entity name (AcmeStoreBundle:User
) from the User
object?
This should always work (no return of Proxy class):
$em = $this->container->get('doctrine')->getEntityManager();
$className = $em->getClassMetadata(get_class($object))->getName();
As getClassMetadata
is deprecated, you can now use getMetadataFor
$entityName = $this->em->getMetadataFactory()->getMetadataFor(get_class($object))->getName();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With