获取实体类的表名 [英] Get table name of entity class

查看:323
本文介绍了获取实体类的表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否知道如何从控制器类中的实体声明中获取表名称

Do you know how to get the table name from an Entity declaration in my controller class

实体类

<?php

namespace Acme\StoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Acme\StoreBundle\Entity\User
 *
 * @ORM\Table(name="users")
 * @ORM\Entity
 */
class User

我现在想要获取用户实体的表名,我如何在我的Symfony2控制器中执行此操作?

I now would like to get the table name of the User entity, how would i do this in my Symfony2 controller?

推荐答案

您将使用的控制器:

$em = $this->getDoctrine()->getManager();
$tableName = $em->getClassMetadata('StoreBundle:User')->getTableName();

请注意, getClassMetadata 方法返回一堆有关该实体的有趣信息。

Note that the getClassMetadata method returns a bunch of interesting info about the entity.

这篇关于获取实体类的表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆