Zend Framework 2 Skeleton布局

时间:2016-02-20 23:35:48

标签: zend-framework zend-framework2

我正在使用Zend Framework 2和Skeleton Application创建一个表单。

我希望我的布局复制默认示例:

enter image description here

如上所示,表单输入会拉伸到屏幕的宽度。产生这个的代码是(仅使用电子邮件地址字段作为示例):

<div class="form-group">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" placeholder="Email" id="exampleInputEmail1" class="form-control">
</div>

当我使用Zend Framework 2(Skeleton应用程序)添加自己的表单元素时,我希望发生相同的结果。但是当我添加一个元素时:

$this->add(array(
         'name' => 'campaign_code',
         'type' => 'Text',             
         'options' => array(
             'label' => 'Campaign Code',
         ),
         'attributes' => array(
            'class'  => 'form-control',
         )                
     ));

生成的HTML是:

<div class="form-group">
    <label>
        <span>Campaign Code</span>
        <input class="form-control" type="text" name="campaign_code">
    </label>
</div>

导致:

enter image description here

请注意labelspan元素周围的input标记是怎样的?我不想要那个。我希望label标记在第一个html示例中关闭。

1 个答案:

答案 0 :(得分:0)

从表单中呈现元素时,表单视图助手非常聪明。

  

添加具有相应元素的id属性

 $this->add(array(
     'name' => 'campaign_code',
     'type' => 'Text',             
     'options' => array(
         'label' => 'Campaign Code',
     ),
     'attributes' => array(
        'class'  => 'form-control',
        'id'  => 'your_id',
     )                
 ));