【发布时间】: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