我正在使用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