【问题标题】:zendframework 2 form populating checkbox values from a databasezendframework 2 表单从数据库中填充复选框值
【发布时间】:2014-02-25 07:08:18
【问题描述】:

我正在使用 zendframework 2 和教义 2。我想从数据库中的值填充复选框的值(依赖注入)。

我的技术来自:https://github.com/doctrine/DoctrineModule/blob/master/docs/form-element.md

这是我的元素(它适用于选择元素,但不适用于复选框):

$this->add(array(
    'type' => 'Zend\Form\Element\MultiCheckbox',
    'name' => 'timesId',
    'options' => array(
        'label' => 'Please Select Your Availablity',
        'value_options' => array(
            'object_manager' => $this->getObjectManager(),
            'target_class'   => 'FormDependencies\Entity\AvailablityTimeTableList',
             'property'       => 'job',
         ),
     ),
     'attributes' => array(
         'value' => '1' //set checked to '1'
     )
 ));

public function getObjectManager()
{
    return $this->objectManager;
}     

我找不到复选框的原生学说 2 方法。

错误信息:

致命错误:不能使用 Doctrine\ORM\EntityManager 类型的对象作为数组

【问题讨论】:

    标签: forms doctrine-orm zend-framework2


    【解决方案1】:

    我已经解决了;

    在类型下我需要指定它的a:

    'type'    => 'DoctrineModule\Form\Element\ObjectMultiCheckbox',
    

    完整代码:

    $this->add(array(
            'type'    => 'DoctrineModule\Form\Element\ObjectMultiCheckbox',
            'name'    => 'timesId',
            'options' => array(
                'label'          => 'Please Select Your Availablity',
                'object_manager' => $this->getObjectManager(),
                'target_class'   => 'FormDependencies\Entity\AvailablityTimeTableList',
                'property'       => 'times',
                'empty_option'   => '--- please choose ---'
            ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 2014-05-12
      • 1970-01-01
      • 2014-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多