【发布时间】:2014-08-23 00:08:15
【问题描述】:
我使用 ZF2+Doctrine+DoctrineMongoODM 模块。我将Person 文档嵌入到House 文档中:
/**
* @ODM\Document
*/
class Custelement{
/** @ODM\EmbedOne(targetDocument="Person") */
protected $person;
所以
#Document is binded to form
$form->bind($document);.
#Common hydrator is used
$form->setHydrator(new \DoctrineModule\Stdlib\Hydrator\DoctrineObject($docManager));
文档House 的公共字段被保存和填充得很好。我使用名称为person 的字段集来编辑嵌入的文档字段,因此有一组带有name=person[firstName] 和name=person[lastName] 的输入元素。
嵌入文档的字段已保存但未填充到表单中。
我找到了一种解决方法 - 只需通过 $vals = (array) $element->getValue(); 获取字段集对象的值,然后
$name = preg_replace("/^(.*)\[(.*)\]$/", "\\2", $elem->getName());
$elem->setValue($vals[$name]); 用于每个字段集元素。
有没有更好的解决方案?
【问题讨论】:
标签: mongodb zend-framework2 fieldset doctrine-odm zend-form2