Zend framework2 如何为每个表单元素放置特殊标记?

Zend framework2 如何为每个表单元素放置特殊标记?,zend-framework2,zend-form,Zend Framework2,Zend Form,我有带字段的表单: $this -> add( array( 'name' => 'firstfield', 'attributes' => array( 'type' => 'text', 'id' => 'id_firstfield' ), 'options' => array(

我有带字段的表单:

$this -> add(
        array(
            'name' => 'firstfield',
            'attributes' => array(
                'type'  => 'text',
                'id' => 'id_firstfield'
            ),
            'options' => array(
                'label' => 'firstfield'
            ),
        )
    );

$this -> add(
        array(
            'name' => 'secondfield',
            'attributes' => array(
                'type'  => 'text',
                'id' => 'id_secondfield'
            ),
            'options' => array(
                'label' => 'secondfield'
            ),
        )
    );
当我使用:

echo $this->formCollection($form);
在我看来,我得到:

[...]
<label for="id_firstfield">first field</label>
<input name="firstfield" type="text" id="id_firstfield" value="">
<label for="id_secondfield">second field</label>
<input name="secondfield" type="text" id="id_secondfield" value="">
[...]
[…]
第一场
第二场
[...]
但我想得到:

[...]
<div id="divforfirstfield">
    <label for="id_firstfield">first field</label>
    <input name="firstfield" type="text" id="id_firstfield" value="">
</div>
<div id="divforsecondfield">
    <label for="id_secondfield">second field</label>
    <input name="secondfield" type="text" id="id_secondfield" value="">
</div>
[...]
[…]
第一场
第二场
[...]

如何执行此操作?

使用
formCollection()
这是不可能的。但是,您可以这样做:

<div id="firstid">
    <?php echo $this->formRow($form->get('firstfield')); ?>
</div>
<div id="secondid">
    <?php echo $this->formRow($form->get('secondfield')); ?>
</div>


如果您只需要一次函数调用就可以轻松地呈现表单,则必须与自己的一位执行此操作的人员一起扩展
formCollection()
查看帮助程序。

使用
formCollection()
这是不可能的。但是,您可以这样做:

<div id="firstid">
    <?php echo $this->formRow($form->get('firstfield')); ?>
</div>
<div id="secondid">
    <?php echo $this->formRow($form->get('secondfield')); ?>
</div>

如果您只需要一次函数调用就可以轻松地呈现表单,那么您必须与自己的一位执行此操作的人员一起扩展
formCollection()
view助手