【问题标题】:Doctrine form element + zf3 error messaje "No object manager was set"Doctrine 表单元素 + zf3 错误消息“未设置对象管理器”
【发布时间】:2017-09-28 17:48:49
【问题描述】:

我使用 Doctrine 在我的表单中创建一个 DoctrineModule\Form\Element\ObjectSelect。但是向我显示了这些错误:“未设置对象管理器”。我基于Doctrine Module 的指南。我进行了一段时间的搜索,但找不到问题所在。代码:

形式:

<?php
//.....
use DoctrineModule\Persistence\ObjectManagerAwareInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Zend\Form\Form;

class SubRubroForm extends Form implements ObjectManagerAwareInterface
{
    private $value_submit;
    private $objectManager;

    public function __construct($value_submit)
    {
        $this->value_submit=$value_submit;
        // Define form name
        parent::__construct('SubRubro-form');

        // Set POST method for this form
        $this->setAttribute('method', 'post');
        $this->addElements();
        $this->addInputFilter();
        $this->init();            
    }

    public function init()
    {
        $this->add([
            'type' => 'DoctrineModule\Form\Element\ObjectSelect',
            'name' => 'rubro',
            'options' => [
                'object_manager' => $this->getObjectManager(),
                'target_class'   => 'Rubros\Entity\Rubro',
                'property'       => 'nombre',
            ],
        ]);
    }
// ... add others elements addElements(){} ....
// ... inputfilters ....
// ... set and get ObjectManager() interface methods...

}

【问题讨论】:

    标签: php forms doctrine-orm zend-framework3


    【解决方案1】:

    从 ObjectManager 加载的父类 Elements 中添加 init() 方法。

    类 SubRubroForm 扩展 Form 实现 ObjectManagerAwareInterface { private $value_submit;私人 $objectManager;

    public function __construct($value_submit)
    {
        $this->value_submit=$value_submit;
        // Define form name
        parent::__construct('SubRubro-form');
    
        // Set POST method for this form
        $this->setAttribute('method', 'post');
        $this->addElements();
        $this->addInputFilter();
        $this->init();            
    }
    
    public function init()
    {
        $this->add([
            'type' => 'DoctrineModule\Form\Element\ObjectSelect',
            'name' => 'rubro',
            'options' => [
                'object_manager' => $this->getObjectManager(),
                'target_class'   => 'Rubros\Entity\Rubro',
                'property'       => 'nombre',
            ],
        ]);
        parent::init();
    }
    // ... add others elements addElements(){} ....
    // ... inputfilters ....
    // ... set and get ObjectManager() interface methods...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2018-02-08
      • 2013-08-18
      • 2013-06-18
      相关资源
      最近更新 更多