2017-09-28 5 views
1

私はフォームにDoctrineModule \ Form \ Element \ ObjectSelectを作成するためにDoctrineを使用しました。しかし、私にはこれらのエラーが表示されます: "オブジェクトマネージャが設定されていません"。私はDoctrine Moduleのガイドに基づいています。私は時間を探していますが、何が間違っているのか分かりません。コード:Doctrineフォームの要素+ zf3エラーmessaje "オブジェクトマネージャが設定されていません"

形式:

<?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... 

} 

答えて

0

は元素のObjectManagerロード細かい父クラスからのinit()メソッドを追加します。

class SubRubroForm extendsフォームは、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... 
関連する問題