[英]Zend create decorator for all form elemets
我用了一個裝飾
$this->getElement('usr_name')->addDecorator('Label', array('class' => 'control-label'));
也許是裝飾ALL
表單labels
更快解決方案?
您可以實現一個函數,將裝飾器添加到表單的所有元素
如果$form
是表單對象。 實現一個函數,該函數將遍歷$form
對象的輸入元素,並在每個元素上添加裝飾器
function addLabelDecorator($form)
{
$formElements = $form->getElements();
foreach($formElements as $element)
$element->addDecorator('Label', array('class' => 'control-label'));
return $form;
}
將元素添加到表單后,使用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 Bootstrap,則已經實現了以下解決方案: EasyBib_Form_Decorator
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.