Doctrine orm Zend Framework 2通过条令实体上的注释形成集合元素

Doctrine orm Zend Framework 2通过条令实体上的注释形成集合元素,doctrine-orm,zend-framework2,Doctrine Orm,Zend Framework2,我有一个安装/配置了条令的Zend Framework 2项目。我直接在实体上使用Zend表单注释来生成表单以显示/编辑实体数据。我遇到了一个问题: 具有多个关系中配置的子实体(区域)集合的实体(供应商)。理论关系运行良好,但是我添加了zend表单注释 /* * ...doctrine annotations... * @Annotation\Type("Zend\Form\Element\Collection") * @Annotation\Options({"label":"Terri

我有一个安装/配置了条令的Zend Framework 2项目。我直接在实体上使用Zend表单注释来生成表单以显示/编辑实体数据。我遇到了一个问题:

具有多个关系中配置的子实体(区域)集合的实体(供应商)。理论关系运行良好,但是我添加了zend表单注释

/*
 * ...doctrine annotations...
 * @Annotation\Type("Zend\Form\Element\Collection")
 * @Annotation\Options({"label":"Territory", "target_element": {"type": "\DocurepVendor\Form\TerritoryFieldset"}})
 */
创建我创建的fieldset对象,但不要将字段名命名为数组。(输入都命名为city,而不是city[]),因此当我提交更新表单时,映射程序需要一个数组,但只找到一个字符串,结果失败

这是我的字段集代码

TerritoryFieldset.php
namespace DocurepVendor\Form;

use \Zend\Form\Fieldset;
use \Zend\InputFilter\InputFilterProviderInterface;

class TerritoryFieldset extends Fieldset implements InputFilterProviderInterface {

    public function __construct($name = null, $options = array()) {
        parent::__construct('Locations', $options);
        $this->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods())
                ->setObject(new \DocurepLocation\Entity\Territory());

        $this->add(array(
            'name' => 'city',
            'options' => array(
                'label' => 'City'
            ),
            'attributes' => array()
        ))->add(array(
            'name' => 'state',
            'options' => array(
                'label' => 'State'
            ),
            'attributes' => array(
                'required' => 'required'
            )
        ));
    }

    public function getInputFilterSpecification() {
        return array();
    }

}
如果我将字段集中的名称设置为“city[]”而不是“city”,则字段集甚至不会填充条令数据


我不确定这是否是我需要在子元素字段集、父元素的注释中完全配置的东西,或者如果这根本无法完成,我需要以另一种方式实现它。有人能给我一个正确的方向吗?

我想你应该使用Hydrator而不是\Zend\Stdlib\Hydrator\ClassMethods()


我将尝试一下,看看它是否能像我所希望的那样处理集合。谢谢。@Fousheezy你能让它工作吗?我很难使用集合和注释…
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;

..

$this->setHydrator(new DoctrineHydrator())