Php Zend表单装饰器添加类

Php Zend表单装饰器添加类,php,zend-framework,zend-form,zend-decorators,Php,Zend Framework,Zend Form,Zend Decorators,我是Zend的新手,也是php的初学者。我有一个生成几个元素的表单。我已经添加了装饰器,使每个装饰器都位于一个div中: $element->addFilter('StringTrim')->addDecorators(array('clearfix'=>new Zend_Form_Decorator_HtmlTag(array('tag'=>'div','class'=>'clearfix')))); 我生成的html如下所示: <div clas

我是Zend的新手,也是php的初学者。我有一个生成几个元素的表单。我已经添加了装饰器,使每个装饰器都位于一个div中:

$element->addFilter('StringTrim')->addDecorators(array('clearfix'=>new Zend_Form_Decorator_HtmlTag(array('tag'=>'div','class'=>'clearfix'))));
我生成的html如下所示:

    <div class="clearfix">
        <dt id="email-label"><label for="email" class="optional">Email</label></dt>
        <dd id="email-element">
        <input type="text" name="email" id="email" value="" class="text" maxlength="100">    
        </dd> 
    </div>
有人有主意吗? 谢谢

试试这个:

$element = new Zend_Form_Element_Text('email'); 
$element->addDecorators(array(array('HtmlTag',array('tag' => 'dd', 'class' => 'yourclass' )));
试试这个

$deco_html_tag = $element->getDecorator('HtmlTag');
$deco_html_tag->setOption('class', 'clearfix');

这里有另一种不用装饰的方法

您可以将其添加到表单类中

$this->setElementDecorators(array(
       'ViewHelper'
));
在你的视图中呈现你的形状

<form class="your-class" id="<?php echo $this->form->getAttrib('id'); ?>" name="<?php echo $this->form->getAttrib('name'); ?>" action="<?php echo $this->escape($this->form->getAction()); ?>" method="<?php echo $this->escape($this->form->getMethod()); ?>">

<div class="something"> 
     <?php echo $this->form->getElement('element')->getLabel();  ?>
</div>
<div class="something"> 
     <?php echo $this->form->getElement('element');  ?>
</div>
</form?

你能发布整个表单吗?这是一个长表单,我编辑并添加元素部分;)它可以工作,但是它删除了'id',所以我像$email->addDecorators那样添加它(数组(数组('HtmlTag',数组('tag'=>'dd','class'=>'clearfix','id'=>'email元素'));谢谢@我很高兴能帮上忙。
$this->setElementDecorators(array(
       'ViewHelper'
));
<form class="your-class" id="<?php echo $this->form->getAttrib('id'); ?>" name="<?php echo $this->form->getAttrib('name'); ?>" action="<?php echo $this->escape($this->form->getAction()); ?>" method="<?php echo $this->escape($this->form->getMethod()); ?>">

<div class="something"> 
     <?php echo $this->form->getElement('element')->getLabel();  ?>
</div>
<div class="something"> 
     <?php echo $this->form->getElement('element');  ?>
</div>
</form?