Doctrine form element + zf3 error message "No object manager was set"

0

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();?>
    
asked by Darwin Carrizo 28.09.2017 в 21:13
source

1 answer

0

Adding the init of the parent class Elements correctly loads the ObjectManager

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',
            ],
        ]);
        parent::init();
    }
// ... add others elements addElements(){} ....
// ... inputfilters ....
// ... set and get ObjectManager() interface methods...
    
answered by 28.09.2017 в 22:16