2011-11-15 70 views
0

如果添加一個窗體(所謂的「第一步」),你有這樣的代碼:Zend框架裝飾DL和DD風格

<dl class="zend_form"> 
    <dt id="Step1-label"></dt> 
    <dd id="Step1-element"> 
     <fieldset id="fieldset-Step1" class="Step"> 
      <dl> 
       ..... 
      </dl> 
     </fieldset> 
    </dd> 
</dl> 

我怎樣才能在DL標籤和DD標籤添加一個類? 例如:

<dl class="Step1DL"> 
<dd id="Step1-element" class="Step1DD"> 

我如何使用Zend裝飾辦呢?再次

謝謝...

回答

1

試試下面的表格範本文件中的代碼,

<?php 
class Admin_Model_Form_Test extends Zend_Form 
{ 
public $elementDecorators = array(
      'ViewHelper', 
      'Errors', 
      array(array('data' => 'HtmlTag'), array('tag' => 'dd')), 
      array('Label', array('tag' => 'dt','class'=>'labmyaccountR'), 
     )); 
public $requiredElementDecorators = array(
      'ViewHelper', 
      'Errors', 
      array('Description',array('escape'=>false,'tag'=>'span', 'placement' => 'append')), 
      array(array('data' => 'HtmlTag'), array('tag' => 'dd')), 
      array('Label', array('tag' => 'dt','class'=>'labmyaccountR'), 
     ));  
    public function EditForm($data = array()) 
    { 
     $this->setMethod(Zend_Form::METHOD_POST); 
     $this->setEncType(Zend_Form::ENCTYPE_MULTIPART); 
      $this->setAction(
       $this->getView()->getHelper('url')->url(array(
       'controller' => 'test', 
       'action'=>'edittest' 
      )) 
      ); 

     $this->setDecorators(array(
       'Description', 
       'FormElements', 
       'Form' 
     )); 

     $fnameNotEmpty = new Zend_Validate_NotEmpty(); 
     $fnameNotEmpty->setMessage('Tax value should not be empty'); 
     $fnameStrlen = new Zend_Validate_StringLength(1, 20); 

     $name = new Zend_Form_Element_Text('taxvalue', array(
      'label' => 'Sales Tax *', 
      'value' => $data['value'], 
      'class' => 'text-size text', 
      'tabindex' => '1', 
      'required' => true, 
      'validators' => array(
       array($fnameNotEmpty, true), 
       array($fnameStrlen, true) 
     ), 
      'filters' => array('StringTrim'), 
        'decorators' => $this->requiredElementDecorators,      
     )); 
     $name->addValidator('Float',true); 
     $this->addElement($name); 

     $submit = new Zend_Form_Element_Submit('submit', array(
       'label' => 'Update', 
       'tabindex' => '20', 
          'decorators' => $this->elementDecorators,      
      )); 
       $submit->removeDecorator('Label'); 
     $submit->removeDecorator('label'); 
     $this->addElement($submit); 
     $id = new Zend_Form_Element_Hidden('tax_id', array(
      'value' => $data['tax_id'] 
     )); 
     $id->removeDecorator('label'); 
     $this->addElement($id); 
     return $this; 
    } 
    } 
?> 
+0

您好,感謝爲你的答案...我試圖使用它是這樣的: $ SubForm_Step = new Zend_Form_SubForm(); $ SubForm_Step-> addDecorators($ elementDecorators);我得到這個exeng: 警告:異常由形式捕獲:方法getType不存在堆棧跟蹤:#0 C:\ xampp \ php \ Zend \ Form \ Decorator \ ViewHelper.php(92):Zend_Form - > __ call('getType',Array)#1 .... – Samuele

+0

所以我試過這樣: $ SubForm_Step-> addDecorator(array('data'=>'HtmlTag' ),array('tag'=>'dd','class'=>'classnamedd')); 但它產生另一個DD元件 \t \t

\t
\t 我想修改已經存在的不是創建另一個.... – Samuele

0

試試這個,你創建的元素之後: 例如:

$element = new Zend_Form_Element_Text('anelement'); 
$element->addDecorators(array(array('HtmlTag',array('tag' => 'dd', 'class' => 'yourclass')));