获取表单扩展Symfony2中的实体元数据

时间:2015-02-17 12:56:09

标签: php forms symfony entity metadata

当我这样做时,我尝试获取实体元数据:

$entityMetadata = $this->validator->getMetadataFactory()->getMetadataFor('Acme\DemoBundle\Entity\Post');

一切正常,但是当我这样做时:

$entityMetadata = $this->validator->getMetadataFactory()->getMetadataFor($formData);

$formData等于string 'Acme\DemoBundle\Entity\Post' (length=27)

我收到了错误:

Cannot create metadata for non-objects. Got: NULL

我做错了什么?有人能帮助我吗?谢谢!

1 个答案:

答案 0 :(得分:0)

根据getMetadataFor签名(http://www.doctrine-project.org/api/orm/2.3/class-Doctrine.ORM.Mapping.ClassMetadataFactory.html),您必须传递一个字符串。也许你应该尝试类似的东西:

$entityMetadata = $this->validator->getMetadataFactory()->getMetadataFor(get_class($formData));