当我这样做时,我尝试获取实体元数据:
$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
我做错了什么?有人能帮助我吗?谢谢!
答案 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));