Doctrine orm ZF2 Doctrine2使用日期字段填充表单

Doctrine orm ZF2 Doctrine2使用日期字段填充表单,doctrine-orm,zend-framework2,twitter-bootstrap-3,Doctrine Orm,Zend Framework2,Twitter Bootstrap 3,尝试将日期字段传递给表单时出错。错误是:为转义助手提供了对象,但标志不允许递归这是由于mysql中有两个日期类型的字段造成的 我写下了脚本的一部分,如果需要进一步的信息,请告诉我。。。 在我的控制器中,我有: public function editAction() { $id = (int) $this->params()->fromRoute('id', NULL); if (!isset($id)) return $this->redir

尝试将日期字段传递给表单时出错。错误是:为转义助手提供了对象,但标志不允许递归这是由于mysql中有两个日期类型的字段造成的

我写下了脚本的一部分,如果需要进一步的信息,请告诉我。。。 在我的控制器中,我有:

public function editAction() {

    $id = (int) $this->params()->fromRoute('id', NULL);
    if (!isset($id))
        return $this->redirect()->toRoute('group', array('action' => 'add'));

    $this->layout('layout/modal');

    $objectManager = $this->_getEntityManager();

    $group = $this->_getEntityManager()->find('Hotbed\Entity\Group', $id);
    $form = new \Hotbed\Form\Group\EditGroup($objectManager);
    $form->bind($group);

    $prg = $this->prg();
    if ($prg instanceof \Zend\Http\PhpEnvironment\Response) {
        // returned a response to redirect us
        return $prg;
    } elseif ($prg === false) {
        // this wasn't a POST request, but there were no params in the flash messenger
        // probably this is the first time the form was loaded

        return array(
            'id' => $id,
            'form' => $form,
        );
    }

    $form->setData($prg);


    if ($form->isValid()) {.......
在我的田野里,我有

class GroupFieldset extends Fieldset implements InputFilterProviderInterface {

protected $_om = '';

public function __construct(ObjectManager $objectManager) {

    parent::__construct('group');

    $this->_om = $objectManager;

    $this->setHydrator(new DoctrineHydrator($this->_om, 'Hotbed\Entity\Group'))
            ->setObject(new Group());

    // Id
    $this->add(array(
        'name' => 'id',
        'attributes' => array(
            'type' => 'hidden',
        ),
    ));

    // Title
    $this->add(array(
        'name' => 'title',
        'type' => 'text',
        'options' => array(
            'label' => 'Title',
        ),
        'attributes' => array(
            'class' => 'form-control input-large',
            'placeholder' => "Enter name of group",
            'required' => '*'
        ),
    ));

    //Root_Parents
    $this->add(array(
        'name' => 'parent',
        'type' => 'select',
        'options' => array(
            'label' => 'Parent group',
            'empty_option' => 'To define sub-groups, select parent',
            'value_options' => $this->_getMainGroups()
        ),
        'attributes' => array(
            'class' => 'form-control input-large',
        ),
    ));

    //State
    $this->add(array(
        'name' => 'state',
        'type' => 'checkbox',
        'options' => array(
            'label' => 'Is Group actif?',
            'use_hidden_element' => true,
            'checked_value' => 1,
            'unchecked_value' => 0
        ),
        'attributes' => array(
            'class' => 'form-control'
        ),
    ));

    //valid from
    $this->add(array(
        'name' => 'valid_from',
        'type' => 'text',
        'options' => array(
            'label' => 'Valid from:',
            'format' => 'd-m-Y'
        ),
        'attributes' => array(
            'placeholder' => 'dd-mm-yyyy',
            'class' => 'form-control input-large date date-picker',
            'readonly' => TRUE,
        ),
    ));



    //valid to
    $this->add(array(
        'name' => 'valid_to',
        'type' => 'text',
        'options' => array(
            'label' => 'Valid to:',
            'format' => 'd-m-Y'
        ),
        'attributes' => array(
            'placeholder' => 'dd-mm-yyyy',
            'class' => 'form-control input-large date date-picker',
            'readonly' => TRUE,
        ),
    )); ......
在这里输入valid_from和valid_to to date的类型(而不是文本)将起作用,但booststrap3日期选择器将替换为html5日期,并且表单不再起作用。 表单如下所示:

<div class="form-group">
                    <label class="col-md-4 control-label"><?php echo $this->formLabel($group->get('valid_from')); ?></label>
                    <div class="col-md-8"><?php echo $this->formInput($group->get('valid_from')); ?></div>
                </div>
                <div class="form-group">
                    <label class="col-md-4 control-label"><?php echo $this->formLabel($group->get('valid_to')); ?></label>
                    <div class="col-md-8"><?php echo $this->formInput($group->get('valid_to')); ?></div>
                </div>

我真的不知道如何解决这个问题。。。感谢您的帮助。

找到了答案: 在将组绑定到表单之前的控制器中,我设置了日期的格式,因此只传递字符串,不再传递对象