2013-07-24 35 views

回答

0

將元素添加到表單後,使用setElementDecorators爲它們指定裝飾器。

Exampe:

class Form_Example extends Zend_Form 
{ 

    public function init() 
    { 
     /* creating form elements*/ 



     // specify all element decorators  
     $this->setElementDecorators(array(
      'ViewHelper', 
      array('Label', array('class' => 'control-label')), 
     )); 

     // specify all form decorators 
     $this->setDecorators(array(
      'FormElements', 
      'Form' 
     )); 
    } 
} 

然而,如果你試圖整合Zend_Form和Twitter的引導,目前已經實施的解決方案,如:EasyBib_Form_Decorator

1

您可以實現如下功能:在裝飾添加到所有形式的元素

如果$form是表單對象。實現一個函數,該函數將遍歷對象的輸入元素並在每個元素上添加裝飾器

function addLabelDecorator($form) 
{ 
    $formElements = $form->getElements(); 
    foreach($formElements as $element) 
     $element->addDecorator('Label', array('class' => 'control-label')); 

    return $form; 
}