Forms Zend Framework 2 formInput或formElement ID标记未呈现

Forms Zend Framework 2 formInput或formElement ID标记未呈现,forms,twitter-bootstrap,zend-framework2,zend-form2,Forms,Twitter Bootstrap,Zend Framework2,Zend Form2,在Zend framework 2中,当我使用视图的formRow方法时 $this->formRow($form->get('product_name')); 它会像这样生成HTML <label for="product_name"> <span>Name</span> <input type="text" id="product_name" name="product_name"> </label>

在Zend framework 2中,当我使用视图的formRow方法时

$this->formRow($form->get('product_name'));
它会像这样生成HTML

<label for="product_name">
    <span>Name</span>
    <input type="text" id="product_name" name="product_name">
</label>

名称
但是如果我使用输入

<div class="control-group">
    <?php echo $this->formLabel($form->get('product_name')->setLabelAttributes(array('class'=>'control-label'))); ?>
    <div class="controls">
        <?php echo $this->formInput($form->get('product_name')); ?>
    </div>
</div>

$this->formInput($form->get('product_name'));

$this->formInput($form->get('product_name'));
我没有身份证

<input type="" name="product_name">

我尝试过使用formElement,但效果相同

如何让它只渲染具有所有属性和值的输入?

这就是我的Zend Framework 2视图的外观(简化)


以及Zend Framework 2表单

<?php
namespace Product\Form;

use Zend\Form\Form;

class ProductForm extends Form
{
    public function __construct($name = null)
    {
        // we want to ignore the name passed
        parent::__construct('product');
        $this->setAttribute('method', 'post');
        $this->setAttribute('class','form-horizontal');

        $this->add(array(
            'name' => 'product_name',
            'attributes' => array(
                'type'  => 'text',
            ),
            'options' => array(
                'label' => 'Name',
            ),
        ));

        $this->add(array(
            'name' => 'submit',
            'attributes' => array(
                'type'  => 'submit',
                'value' => 'Save',
                'id' => 'submitbutton',
                'class'=>'btn btn-success btn-large'
            ),
        ));
    }
}
?>

更改:

    $this->add(array(
        'name' => 'product_name',
        'attributes' => array(
            'type'  => 'text',
        ),
        'options' => array(
            'label' => 'Name',
        ),
    ));
致:

实际上,这个代码:

 $this->add(array(
        'type' => 'Zend\Form\Element\Text',
        'name' => 'product_name',
        'attributes' => array(
            'id'    => 'product_name',
            'class' => 'span3',
        ),
        'options' => array(
            'label' => 'Your label',            
        ),
    ));
由于
$this->formRow(…)
表单帮助程序将生成以下内容,因此可以由类似引导的css呈现程序正确使用:

<label for="product_name">Your label</label><input type="text" name="product_name" class="span3" id="product_name" value="">
您的标签

它比原始的
formRow
输出更可读(没有id也没有类属性)

当前的Zend 2不会生成这样的表单。。。。。。。。。。。。。
 $this->add(array(
        'type' => 'Zend\Form\Element\Text',
        'name' => 'product_name',
        'attributes' => array(
            'id'    => 'product_name',
            'class' => 'span3',
        ),
        'options' => array(
            'label' => 'Your label',            
        ),
    ));
<label for="product_name">Your label</label><input type="text" name="product_name" class="span3" id="product_name" value="">