2013-07-01 5 views
1

배치 태그의 클래스 속성에 input-element 유형을 추가하는 방법이 있습니까? 아래의 예제 코드에서는 이미 '요소'또는 LI 태그의 클래스를 가진 'Div'데코레이터가 될 수 있습니다.ZF1 : 태그 묶음 입력 필드에 클래스로 입력 유형 추가

(나는 몇 가지 코드를 ommitted 한)

class My_Form extends Zend_Form 
{ 
    public function loadDefaultDecorators($disableLoadDefaultDecorators = false) 

    //Set the decorators we need: 
    $this->setElementDecorators(array(
     'ViewHelper', 
     'Errors', 
     array('Description', array('tag' => 'p', 'class' => 'description', 'escape' => false)), 
     array('decorator' => array('Div' => 'HtmlTag'), 'options' => array('tag' => 'div', 'class' => 'element')), 
     array('Label', array('escape' => false)),   
     array('decorator' => array('Li' => 'HtmlTag'), 'options' => array('tag' => 'li')),   
    )); 
    } 
} 

하거나 My_Form_Element를 만들고를 automaticly 모든 Zend_Form_Element_XXX 그에서 연장 가질 수 있다면.

나는 그냥 방법 렌더링 오버라이드 (override)이

<form> 
    <ul> 
    <li> 
     <label for="contactForm-contact_subject" class="optional">Regarding:</label> 
     <div class="element form-input-text"><input type="text" name="contactForm[contact_subject]" id="contactForm-contact_subject" value="" /></div> 
    </li> 
    <li> 
     <label for="contactForm-contact_message" class="required">Message:</label> 
     <div class="element form-textarea"><textarea name="contactForm[contact_message]" id="contactForm-contact_message" rows="24" cols="80"></textarea></div> 
    </li> 
    <li> 
     <div class="element form-input-submit"><input type="submit" name="contactForm[form_contact_submit]" id="contactForm-form_contact_submit" value="form_contact_submit" /></div> 
    </li> 
    </ul> 
</form> 

답변

1

같은 마크 업 함께 종료 싶습니다 : 마법처럼 일했다

class My_Form extends Zend_Form 
{ 
    public function loadDefaultDecorators($disableLoadDefaultDecorators = false) 
    { 
     //Set the decorators we need: 
     $this->setElementDecorators(array(
      'ViewHelper', 
      'Errors', 
      array('Description', array('tag' => 'p', 'class' => 'description', 'escape' => false)), 
      array('decorator' => array('Div' => 'HtmlTag'), 'options' => array('tag' => 'div', 'class' => 'element')), 
      array('Label', array('escape' => false)),   
      array('decorator' => array('Li' => 'HtmlTag'), 'options' => array('tag' => 'li')),   
     )); 
    } 

    public function render(Zend_View_Interface $view = null) 
    { 
     /* @var $element Zend_Form_Element */ 
     foreach ($this->getElements() as $element) { 
      $type = end(explode('_', $element->getType())); 
      $element->getDecorator('Div')->setOption('class', 
       sprintf('%s form-%s', 'element', strtolower($type))); 
     } 

     return parent::render($view); 
    }  
} 
+0

을! – Phliplip