2009-09-09 2 views
2

보기 스크립트를 데코레이터로 사용하기 위해 양식을 전환하는 중입니다. 내가 본 예제는 지금까지보기 스크립트에서 다음을 수행하십시오젠드 폼 - 뷰 스크립트에 표시 할 폼 클래스에서 레이블 값을 추출하는 방법?

<td><label for='textEmail'>Email:</label></td> 
<td><?php echo $this->element->textEmail; ?></td> 

나뿐만 아니라 양식 개체에서 레이블에 표시 할 텍스트를 가질 수있는 방법을 찾아야하고 싶습니다.

class RegisterForm extends Zend_Form { 
public function init() { 
    $this->setAction('') 
     ->setMethod('post') 
     ->setAttrib('id','formRegister'); 

    $this->addElement('text', 'textEmail', array('label' => 'Email: ')); 
    $oEmail = $this->getElement('textEmail') 
     ->setRequired(true) 
     ->addFilter('StringTrim') 
     ->addValidator('EmailAddress'); 
    $oEmail->setDecorators(array('ViewHelper', 'Errors')); 

    $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/RegisterForm.phtml')))); 
    } 
} 

위의 내용은 내 양식 객체 정의 방법입니다. 정의 된 레이블 값에 액세스하는 방법을 알고있는 사람이 있습니까? 아마도 다음과 같은 형식입니까?

<?php echo $this->element->textEmail->label; ?> 

당연히 작동하지 않습니다. : P 감사합니다 ~

답변

6

$ this-> 엘리먼트 -> getLabel()

다음

표준 필드 내보기 스크립트입니다 :

<div class="field<?php if($this->element->hasErrors()): ?> errors<?php endif; ?>" id="field_<?php echo $this->element->getId(); ?>"> 
    <?php if (0 < strlen($this->element->getLabel())) : ?> 
     <?php echo $this->formLabel($this->element->getName(), $this->element->getLabel());?> 
    <?php endif; ?> 
    <span class="value"><?php echo $this->{$this->element->helper}(
     $this->element->getName(), 
     $this->element->getValue(), 
     $this->element->getAttribs() 
    ) ?></span> 
    <?php if ($this->element->hasErrors()) : ?> 
     <?php echo $this->formErrors($this->element->getMessages()); ?> 
    <?php endif; ?> 
    <?php if (0 < strlen($this->element->getDescription())) : ?> 
     <span class="hint"><?php echo $this->element->getDescription(); ?></span> 
    <?php endif; ?> 
</div> 
+1

당신은 나의 10 분, 엄지 손가락 (y)를 저장 업에 대한 그것. – NullPointer

관련 문제