【问题标题】:How to create a ZF2 FormCollection of the Doctrine ORM Module's ObjectSelect elements?如何创建 Doctrine ORM 模块的 ObjectSelect 元素的 ZF2 FormCollection?
【发布时间】:2014-10-10 17:38:22
【问题描述】:

我有一个奇怪的情况,我的添加表单运行良好,但编辑表单甚至无法加载。相反,我收到以下错误:

注意:未定义的属性:/vendor/zendframework/zendframework/library/Zend/Form/Element/Collection.php 第 517 行中的 DoctrineModule\Form\Element\ObjectSelect::$object

致命错误:类名必须是 /vendor/zendframework/zendframework/library/Zend/Form/Element/Collection.php 第 517 行中的有效对象或字符串

我有 Application\Model\Record 类的对象,它们与 Application\Model\Subject 类的对象具有多对多关系。我希望SubjectsRecord 表单中显示为下拉列表,并可选择添加多个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
Doctrine-orm-module 0.8.0
教义 2.4.2

【问题讨论】:

    标签: orm doctrine-orm zend-framework2


    【解决方案1】:

    看起来这是 ZF2 上的一个错误,目标元素需要是一个字段集才能工作,否则会遇到这个问题。使用字段集来包装 ObjectSelect。

    【讨论】:

    • 终于解决了这个问题。将 ObjectSelect 包装在 Fieldset 中可以使编辑页面正常工作。谢谢!
    猜你喜欢
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多