我正在使用zendframework 2和doctrine 2.我想從我的數據庫中的值中填充MultiCheckbox的值。 我得到了技術來源:https://github.com/doctrine/DoctrineModule/blob/master/docs/form-element.mdzendframework 2表單從數據庫中填充MultiCheckbox的值
namespace Users\Form;
use Zend\Form\Form;
use DoctrineModule\Persistence\ObjectManagerAwareInterface;
use Doctrine\Common\Persistence\ObjectManager;
class addForm extends form implements ObjectManagerAwareInterface
{
protected $objectManager;
public function setObjectManager(ObjectManager $objectManager)
{
$this->objectManager = $objectManager;
}
public function getObjectManager()
{
return $this->objectManager;
}
public function __construct($name = null)
{
parent::__construct('add');
$this->setAttribute('method', 'post');
$this->setAttribute('enctype','multipart/formdata');
$this->add(array(
'type' => 'DoctrineModule\Form\Element\ObjectMultiCheckbox',
'name' => 'option',
'options' => array(
'label' => 'Options Véhicule',
'object_manager' => $this->getObjectManager(),
'target_class' => 'Users\Entity\optionsvehicule',
'property' => 'property'
, )));
我收到錯誤消息: 沒有對象管理器設置。
它是通過依賴注入來設置的嗎? – alex
@alex怎麼可能'__construct'調用了方法'$ this-> getObjectManager()',這是以前不能設置的。 – AlexP
沒有在構造函數中看到它...這就是爲什麼它是一個問題 – alex