我有一个奇怪的情况,我的添加表单完美工作,但编辑表单甚至不会加载。相反,我得到以下错误:如何创建Doctrine ORM模块的ObjectSelect元素的ZF2 FormCollection?
Notice: Undefined property: DoctrineModule\Form\Element\ObjectSelect::$object in /vendor/zendframework/zendframework/library/Zend/Form/Element/Collection.php on line 517
Fatal error: Class name must be a valid object or a string in /vendor/zendframework/zendframework/library/Zend/Form/Element/Collection.php on line 517
我有有到类Application\Model\Subject
的对象很多一对多关系类Application\Model\Record
的对象。我希望Subjects
在Record
表单中显示为下拉列表,并且可以添加多个Subjects
。所以在RecordFieldset.php
我:
$this->add(array(
'name' => 'subjects',
'type' => 'Zend\Form\Element\Collection',
'options' => array(
'label' => 'Subjects',
'count' => 1,
'should_create_template' => true,
'allow_add' => true,
'allow_remove' => true,
'template_placeholder' => '__subjectindex__',
'target_element' => array (
'name' => 'subject',
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'options' => array(
'object_manager' => $this->objectManager,
'target_class' => 'Application\Model\Subject',
'property' => 'name',
'empty_option' => 'Select a subject',
),
'attributes' => array(
'class' => 'form-control',
),
),
),
));
就像我说的,这完全在记录添加形式。但它看起来像编辑窗体上无法加载主题。有没有人尝试过这样的事情?或者你知道错误在说什么吗?
环境:
Zend框架2.3.3
学说-ORM模块0.8.0
学说2.4.2
终于找到了解决这个问题。在Fieldset中包装ObjectSelect使编辑页面正常工作。谢谢! – Nick 2014-11-10 19:18:02