0
我想添加「DoctrineModule \表格\元素\ ObjectSelect」我的形式,但它不斷給我這個錯誤:沒有對象管理器設置DoctrineModule 表格元素 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),並給出了相同的錯誤;沒有設置對象管理器。 – dino