2012-08-05 4 views
1

이 기능을 작동시키려는 노력의 시간이 지나면 나는 당신에게 의지하고 있습니다. ViewScript 데코레이터로 사용자 정의 양식을 렌더링하고 표시 할 오류 메시지를 가져올 수 없습니다. 나는 여기에서 찾은 많은 다른 솔루션을 시도했지만 getErrorMessages()는 항상 비어 있습니다. Zend Form ViewScript 오류 메시지를 표시하는 방법

public function init() { 
    $this->setDecorators(array('Errors', array('ViewScript', array('viewScript' => '_forms/_login.phtml')))); 

    $this->setName('loginform');$username = new Zend_Form_Element_Text('username'); 
    $username->setAttrib('size', '35'); 
    $username->setRequired(true); 
    $username->addValidator('NotEmpty'); 
    $username->setDecorators(array('ViewHelper', 'Errors')); 

    $password = new Zend_Form_Element_Password('password'); 
    $password->setRequired(true); 
    $password->addValidator('NotEmpty'); 
    $password->setDecorators(array('ViewHelper', 'Errors')); 

    $submit = new Zend_Form_Element_Button('submit'); 
    $submit->setAttrib('type', 'submit'); 
    $submit->setDecorators(array('ViewHelper', 'Errors')); 

    $this->setMethod('post'); 
    $this->setAction('/auth/index'); 

    $this->addElements(array($username, $password, $submit)); 
} 
} 

내 viewscript입니다 :

이 내 로그인 폼입니다

<form action="<?php echo $this->element->getAction() ?>" name="<?php echo $this->element->getName() ?>" method="<?php echo $this->element->getMethod() ?>" id="login-form"> 
<ul class="nav"> 
<li><?php echo $this->element->username; ?></li> 
<li><?php echo $this->element->password; ?></li> 
<li><?php echo $this->element->submit; ?></li> 
</ul> 

그리고 이것은 내 처리 작업입니다 :

public function indexAction() 
{ 
    $request = $this->getRequest(); 
    $form = new Form_LoginForm(); 
    if ($request->isPost()){ 
     if($form->isValid($this->_request->getPost())) { //This part works 

     } 
     else { 

     }  
    } 
} 

성공 사례가없는 here의 예를 시도했습니다.

아이디어가 있으십니까?

답변

3

이 방법을 사용하면 오류 메시지를 인쇄 할 수 있습니다.

<li><?php echo $this->element->username . 
$this->formErrors($this->element->username->getMessages()); ?></li> 
<li><?php echo $this->element->password. 
$this->formErrors($this->element->password->getMessages()); ?></li> 
<li><?php echo $this->element->submit; ?></li> 
+0

위대한 솔루션을 이용해 주셔서 감사합니다. – mboullouz