2012-09-01 3 views
-3

저는 프로젝트에서 젠드 프레임 워크를 사용하고 있습니다. 나는젠드 양식의 설명을 설정하십시오.

fields marked by * are mandatory

처럼, 내 양식에 대한 설명/메모를 추가 할하지만 난 형태와 방법 데코레이터와 함께 사용하는 방법에 대한 설명을 추가하는 방법을 발견하지 않았다.

도움이 될 것입니다. 감사.

+0

약간의 코드 스 니펫을 넣을 수 있습니까? – bitfox

+1

http://stackoverflow.com/a/5215726/131824 참조 –

답변

1

두 가지 옵션이 있습니다 장식에서

  • 사용 a 또는
  • 사용자 정의를 요소를 만들 수 Zend_Form_Element을 확장
은 매우 일반적이기 때문에 나는 후자로 갈 것

원시 html 코드의 일부를 요소 이전 또는 이후에 양식에 추가 할 수 있습니다.

은 다음과 같이해야합니다 :

class My_Form_Element_Raw extends Zend_Form_Element 
{ 
    protected $raw_html; 
    public function setRawHtml($value) 
    { 
     $this->raw_html = $value; 
     return $this; 
    } 
    public function getRawHtml() 
    { 
     return $this->raw_html; 
    } 
    public function render() 
    { 
     // you can use decorators here yourself if you want, or wrap html in container tags 
     return $this->raw_html; 
    } 
} 

$form = new Zend_Form(); 
// add elements 
$form->addElement(
    new My_Form_Element_Raw(
     'my_raw_element', 
     array('raw_html' => '<p class="highlight">fields marked by * are mandatory</p>') 
    ) 
); 
echo $form->render(); 

Zend_Form_Element을 확장하면 setOption/s, getOption/s 방법을 오버라이드 (override)하는 할 필요 없어요. 젠드는 내부적으로 세트를 사용 ** 보호 특성이 경우 protected $raw_html;public function setRawHtml($value)public function getRawHtml() 는 또한의 두 가지 옵션을 모두 받아 들일 것입니다 귀하의 재산 $raw_html 이름을 지정 같은 요소 옵션을 감지 할 수 'raw_html'각각

'rawHtml'

<div> 
    <h4>fields marked by * are mandatory</h> 
    <?php echo $this->form ?> 
</div> 

또는 전체 FO를 제어 할 viewScript 데코레이터를 사용

0

이들은 일반적으로 사용하는 요소의 데코레이터이며 접두사에 * 및 설명 장식을 포함합니다.

$element->setDescription('fields marked by * are mandatory'); 

그 후에 당신은 스타일 설명 나는이 도움이 되었으면 좋겠 좋은 하루 되세요의 bottomt 어딘가에 표시 할 수 있습니다, 하나 개의 요소에 대한 설명을 추가

는 다음 코드를 사용합니다.

1

양식에 추가 텍스트를 추가하는 가장 쉬운 방법은 페이지 뷰에 적절한 HTML을 추가하는 것입니다 RM 경험 : 당신이 $form->setDescription()를 사용하여 양식에 설명을 추가 할 수 있습니다 그러나

<article class="login"> 
    <form action="<?php echo $this->element->getAction() ?>" 
      method="<?php echo $this->element->getMethod() ?>"> 
     <table> 
      <tr> 
       <th>Login</th> 
      </tr> 
      <tr>fields marked by * are mandatory</tr> 
      <tr> 
       <td><?php echo $this->element->name->renderViewHelper() ?></td> 
      </tr> 
      <tr> 
       <td><?php echo $this->element->password->renderViewHelper() ?></td> 
      </tr> 
      <tr> 
       <td><?php echo $this->element->submit ?></td> 
      </tr> 
     </table> 
    </form> 
</article> 

은 다음 echo $this->form->getDescription()와 그 설명을 렌더링 할 수 있습니다. 아마도 폼 수준 대신 set 및 getTag()와 함께 요소 수준에서 이러한 메서드를 사용하는 것이 좋습니다.

난 그냥 CSS를 사용 별표 단서를 제공한다 :

dt label.required:before { 
    content: "* "; 
    color: #ff0000; 
} 

내가 어떤 당신이 원하는 경우 단지 CSS를 사용하여 원하는 주 표시 할 수있는 확신합니다.

관련 문제