Doctrine orm DoctrineModule\Form\Element\ObjectSelect未设置对象管理器

Doctrine orm DoctrineModule\Form\Element\ObjectSelect未设置对象管理器,doctrine-orm,zend-framework3,Doctrine Orm,Zend Framework3,我正在尝试将“DoctrineModule\Form\Element\ObjectSelect”添加到我的表单中,但它始终给我以下错误:未设置对象管理器 这是我表格的代码: use Zend\Form\Form; use Zend\InputFilter\InputFilter; use Retrieve\Entity\Autos; use Doctrine\Common\Persistence\ObjectManager; use DoctrineModule\Persistence\Obje

我正在尝试将“DoctrineModule\Form\Element\ObjectSelect”添加到我的表单中,但它始终给我以下错误:未设置对象管理器

这是我表格的代码:

use Zend\Form\Form;
use Zend\InputFilter\InputFilter;
use Retrieve\Entity\Autos;
use Doctrine\Common\Persistence\ObjectManager;
use DoctrineModule\Persistence\ObjectManagerAwareInterface;

class AddForm extends Form
{ 
  /**
 * Entity manager.
 * @var Doctrine\ORM\EntityManager 
 */
private $entityManager;

protected $objectManager;

public function __construct()
{
    parent::__construct('addforms');

    $this->setAttribute('method', 'post');

    $this->addElements();
    $this->addInputFilter();  

}

protected function addElements() 
{           
    // Add "title" field
    $this->add([        
        'type'  => 'text',
        'name' => 'title',
        'attributes' => [
            'id' => 'title'
        ],
        'options' => [
            'label' => 'Title',
        ],
    ]);

 $this->add([
        'type' => 'DoctrineModule\Form\Element\ObjectSelect',
        'name' => 'country',
        'options' => [
            'label' => 'Country',
            'object_manager' =>  $this->getObjectManager(),
            'target_class'   => 'BusinessGhana\Entity\Country',
            'property'       => 'country',
            'display_empty_item' => true,
            'empty_item_label'   => '--select Country--',                
        ],
    ]); 
  //other elements here...
}

 public function setObjectManager(ObjectManager $objectManager)
{
    $this->objectManager = $objectManager;
}

public function getObjectManager()
{
    return $this->objectManager;
} 

private function addInputFilter() 
{  
    //  inputfilter elements here...  
}
}
有人能指导我如何解决这个问题吗。
提前感谢。

您的类表单应该实现
ObjectManagerAwareInterface

class AddForm extends Form implements ObjectManagerAwareInterface
{

}

因为类将从
setObjectManager()
方法注入
ObjectManager
ObjectManager接口的实例;没有设置对象管理器。我们通常应该使用FormElementManager而不是直接创建类来实例化表单,然后使用init()而不是官方文档中显示的_构造,这很有意义。然而,无论我在过去的几个小时里做了什么(Laminas),我都无法让它工作。。setObjectManager()方法从未执行,因此没有注入对象管理器。在线找到此线程,因此希望检查过去是否有任何解决方案:)