Zend framework 添加<;部门>;以及要在zf2中形成的类

Zend framework 添加<;部门>;以及要在zf2中形成的类,zend-framework,zend-framework2,Zend Framework,Zend Framework2,我想在这个表单中为每一个添加css类和分区标记。我不知道怎么做。我也可以为标签和输入字段添加类,但不知道如何添加 我的表格是这样的 namespace Erp\Form; use Zend\Form\Form as Form; class LeadsForm extends Form { public function __construct($name = null){ parent::__construct('leads'); $this->

我想在这个表单中为每一个添加css类和分区标记。我不知道怎么做。我也可以为标签和输入字段添加类,但不知道如何添加

我的表格是这样的

namespace Erp\Form;

use Zend\Form\Form as Form;

class LeadsForm extends Form {
    public function __construct($name = null){
        parent::__construct('leads');

        $this->add(array(
            'name' => 'id',
            'type' => 'Hidden',
        ));
        $this->add(array(
            'name' => 'companyName',
            'type' => 'Text',
            'attributes' => array(
                'class' => 'req'
            ),
            'options' => array(
                'label' => 'Company Name',

            ),
        ));
        $this->add(array(
            'name' => 'website',
            'type' => 'Text',
            'options' => array(
                'label' => 'Website',
            ),
        ));
<form method="POST" name="leads" action="&#x2F;erp&#x2F;public&#x2F;leads&#x2F;add" id="leads">

<input type="hidden" name="id" value="">

<div class="formSep">
<label class="req">Company Name</label>
<input type="text" name="companyName" class="req" value="">
</div>

<div class="formSep">
<label class="req">Website</label>
<input type="text" name="website" value="">
</div>
它显示如下(源代码)


公司名称
网站
但我希望这样

namespace Erp\Form;

use Zend\Form\Form as Form;

class LeadsForm extends Form {
    public function __construct($name = null){
        parent::__construct('leads');

        $this->add(array(
            'name' => 'id',
            'type' => 'Hidden',
        ));
        $this->add(array(
            'name' => 'companyName',
            'type' => 'Text',
            'attributes' => array(
                'class' => 'req'
            ),
            'options' => array(
                'label' => 'Company Name',

            ),
        ));
        $this->add(array(
            'name' => 'website',
            'type' => 'Text',
            'options' => array(
                'label' => 'Website',
            ),
        ));
<form method="POST" name="leads" action="&#x2F;erp&#x2F;public&#x2F;leads&#x2F;add" id="leads">

<input type="hidden" name="id" value="">

<div class="formSep">
<label class="req">Company Name</label>
<input type="text" name="companyName" class="req" value="">
</div>

<div class="formSep">
<label class="req">Website</label>
<input type="text" name="website" value="">
</div>

公司名称
网站

我该怎么做

我假设您正在使用此代码来呈现表单

$form = $this->form;
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formCollection($form);
echo $this->form()->closeTag();
虽然这是预期的效果,但对于像您这样的案例,它并没有那么灵活。因此,要在视图文件中以所需的方式呈现表单,必须逐个使用并呈现每个表单输入

 $form = $this->form;
 $form->prepare();
 echo $this->form()->openTag($form);
 echo $this->formHidden($form->get("id"));
 <div class="formSep">
     echo $this->formText($form->get("companyName"));
 </div>
 <div class="formSep">
     echo $this->formText($form->get("website"));
 </div>
 echo $this->form()->closeTag();
$form=$this->form;
$form->prepare();
echo$this->form()->openTag($form);
echo$this->formHidden($form->get(“id”);
echo$this->formText($form->get(“companyName”);
echo$this->formText($form->get(“网站”);
echo$this->form()->closeTag();