2013-03-13 3 views
0
ZF1 양식 및 양식 요소

가보기에 <p>description here</p>로 출력 된 setDescription 방법을했다 .... ZF2는이 방법 이없는 것 같다 그래서 내 질문에 내가 형성하기 위해 설명을 추가 할 수있는 방법입니다 요소들? 당신이 요소는 (컨트롤러) 양식을 만들 때 setLabel 방법을 사용할 수 있습니다 레이블을 의미하는 경우ZF2 폼 요소 설명

<div> 
    <? 
    $form = $this->form; 
    $form->prepare(); 
    echo $this->form()->openTag($form); 

    foreach ($form->getElements() as $el) { 
     ?> 
     <div class="form_element"> 
      <?=$this->formRow($el);?> 
     </div> 
     <? 
    } 
    echo $this->partial('system/form/buttons_form_part.phtml', array('form' => $form)); 
    echo $this->form()->closeTag(); 
    ?> 
</div> 

답변

5

ZF 2.1.5을 사용하여, 하나 개의 솔루션 : 여기

array(
     'spec' => array(
      'name' => 'name', 
      'options' => array(
       'label' => 'Your name', 
      ), 
      'attributes' => array(
       'type' => 'text' 
      ), 
     ) 
    ), 

이 링크입니다 : 당신이 만들 배열을 사용하는 경우

$name = new Element('name'); 
$name->setLabel('Your name'); 

는 또는 양식 요소는이를 사용 setOptions() 일 수 있습니다. 양식 definiton에서

:

$file = new Element\File('file'); 
$file->setLabel('Photo (.jpg, .gif, .png)'); 
$file->setOptions(array('description' => 'test description')); 
… 

폼 요소 렌더링 :

array(1) { ["description"]=> string(16) "test description" } 
+0

대 : 당신이 액세스

$element = $form->get(…); var_dump($element->getOptions()); 

줄 것이다! 그것은 작동 ... –