1
對於一個elment裝飾我用Zend公司所創造的一切形式elemets
$this->getElement('usr_name')->addDecorator('Label', array('class' => 'control-label'));
裝飾也許是更快的解決方案來裝點ALL
形式labels
?
對於一個elment裝飾我用Zend公司所創造的一切形式elemets
$this->getElement('usr_name')->addDecorator('Label', array('class' => 'control-label'));
裝飾也許是更快的解決方案來裝點ALL
形式labels
?
將元素添加到表單後,使用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
您可以實現如下功能:在裝飾添加到所有形式的元素
如果$form
是表單對象。實現一個函數,該函數將遍歷對象的輸入元素並在每個元素上添加裝飾器
function addLabelDecorator($form)
{
$formElements = $form->getElements();
foreach($formElements as $element)
$element->addDecorator('Label', array('class' => 'control-label'));
return $form;
}