簡體   English   中英

Zend為所有形式元素創建裝飾器

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM