I am using Doctrine to create a DoctrineModule \ Form \ Elemen \ ObjectSelect in my forms. But when calling it from the view it shows me this error: 'No object manager was set' ("No object manager has been established"). I rely on the DoctrineModule guide. I've been searching for a while, but I can not find what's wrong. The code:
The forumlario:
<?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...
}
The view:
<h3>vista</h3>
<?php echo $this->form()->openTag($form);?>
<?php echo $this->formElement($form->get('rubro'));?>
<?php echo $this->formElement($form->get('submit'));?>
<?php echo $this->form()->closeTag();?>