2012-12-18 67 views
0

我嘗試從控制器呼應的消息,以查看,並且它甚至不顯示它。Zend的回送消息,以查看

它驗證所有用戶輸入了,把那些是有效的,並顯示這些都不是有效的電子郵件。

但它不顯示這些都不是在提交的時候是按視圖有效的,但它確實把那些有效的。

在這裏有點我的代碼:

<form method="post" action="<?php echo $this->url(array(), 'inviteByEmail'); ?>"> 
      <table><tr> 
       <td>Email Addresses:* <span class="right small_font" style="margin-right:25px;">* Each email address must be separated by a comma (,)</span></td> 
       <td></td> 
      </tr><tr> 
       <td><input class="input_long" type="text" name="emails" /></td> 
      </tr><tr> 
       <td><br/>Personalize your message:</td> 
      </tr><tr> 
       <td><textarea cols="49" rows="7" name="personal_message" id="share-text" style="margin-bottom:8px;" placeholder="Download Ad-Aware and help me get PRO version" ></textarea></td> 
      </tr><tr> 
       <td rowspan="3" valign="top"> 
        <input type="submit" class="btn_submit_step3" id="btn_friends" value="share_friends" /><br/> 
       </td> 
      </tr></table> 
     </form> <?php echo $this->error; ?> 

控制器:

public function inviteByEmailAction() 
{ 
    $emails = $this->getRequest()->getParam('emails'); 
    $personal_message = $this->getRequest()->getParam('personal_message'); 

    $emails = explode(",", $emails); 

    foreach ($emails as $email) 
    { 
     $email = trim($email); 
     $validator = new Zend_Validate_EmailAddress(); 

     // Validate emails that exists in Database 
     $valiadtor_email_in_dbUsers = new Zend_Validate_Db_NoRecordExists (
      array (
       'table' => 'users', 
       'field' => 'email' 
      ) 
     ); 

     $valiadtor_email_in_dbReferrals = new Zend_Validate_Db_NoRecordExists (
      array (
       'table' => 'referrals', 
       'field' => 'email' 
      ) 
     ); 

     if ($validator->isValid($email)) 
     { 
      if ($valiadtor_email_in_dbUsers->isValid($email)) 
      { 
       if ($valiadtor_email_in_dbReferrals->isValid($email)) 
       { 
        if ($this->_helper->model('EmailInvites')->noRowByFields(array('email' => $email, 'referred_by_user_id' => $this->_helper->user()->id))) 
        { 
         $email_invite = $this->_helper->model('EmailInvites')->createRow(); 
         $email_invite->email = $email; 
         $email_invite->personal_message = $personal_message; 
         $email_invite->referred_by_user_id = $this->_helper->user()->id; 
         $email_invite->save(); 

         $this->_helper->user()->sendInviteEmail($email, $personal_message); 
        } 
       } else { 
        echo $email . " already exists"; 
              $this->view->error = $email . " already exists"; 
       } 
      }else { 
        echo $email . " already exists"; 
              $this->view->error = $email . " already exists"; 
       } 
     } 
    } 
    $this->getHelper('redirector')->gotoRoute(array(), 'invite'); 
} 

回答

2

回聲是在inviteByEmailAction()。這意味着,它會在inviteByEmail.phtml視圖中顯示。然而,回聲之後,你在這行重定向到inviteAction。

$this->getHelper('redirector')->gotoRoute(array(), 'invite'); 

這就是爲什麼你看不到顯示的回顯。

如果你不想重定向發生,如果有錯誤,你需要像回聲後添加return語句:

} else { 
       echo $email . " already exists"; 
       $this->view->error = $email . " already exists"; 
       return; 
      } 
     }else { 
       echo $email . " already exists"; 
       $this->view->error = $email . " already exists"; 
       return; 
      } 

如果您想重定向,並顯示錯誤消息,你可以重定向之前使用Flashmessenger幫手。

+0

謝謝,我會試用flashmessager,重定向路徑實際上是重定向到同一頁面。回報給我一個錯誤。 –