阅读Doctrine实体属性的元数据 [英] read metadata of a Doctrine entity property
本文介绍了阅读Doctrine实体属性的元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须遵循实体:
/**
* ProductService
*
* @ORM\Table(name="sf_products_services")
* @ORM\Entity(repositoryClass="Evo\BackendBundle\Entity\ProductServiceRepository")
*/
class ProductService
{
[...]
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=150)
*/
protected $name;
[...]
如何阅读长度 $ name属性的值?我读了我可以使用教义元数据,但是我没有找到任何关于如何使用它以及如何读取这些数据的信息。
How can I read the "length" value of the $name property ? I read I could use doctrine metadata, but I dont find anything about how to use it and how to read these data.
推荐答案
根据@wonde答案,您可以通过教义元数据信息阅读您需要的信息:
In accordion with the @wonde answer you can read the info you need thru the Doctrine metadata info as follow:
$doctrine = $this->getContainer()->get("doctrine");
$em = $doctrine->getManager();
$className = "Evo\BackendBundle\Entity\ProductService";
$metadata = $em->getClassMetadata($className);
$nameMetadata = $metadata->fieldMappings['name'];
echo $nameMetadata['type']; //print "string"
echo $nameMetadata['length']; // print "150"
希望这个帮助
这篇关于阅读Doctrine实体属性的元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文