我尝试从控制器回显一条消息来查看,它甚至都没有显示它。
验证用户输入的所有电子邮件,发送有效的电子邮件并显示无效的电子邮件。
但是当按下提交时,它不会显示那些在视图中无效的内容,但它会发送有效的内容。
这是我的一些代码:
<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');
}
答案 0 :(得分:2)
echo在inviteByEmailAction()中。这意味着,它将显示在inviteByEmail.phtml视图中。但是,在回显之后,您将在此行重定向到inviteAction。
$this->getHelper('redirector')->gotoRoute(array(), 'invite');
这就是为什么你看不到显示的回声。
如果您不希望在出现错误时发生重定向,则需要在echo之后添加一个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帮助程序。