【发布时间】:2012-03-05 05:08:31
【问题描述】:
更新:
RJZ:
TdjxQetc 是来自数据库的$activateCode,所以当我运行 /confirm/ 时,我应该会感到抱歉,您没有正确的激活码,因为我没有传入任何 var ($activateCode) 但是当我运行 /confirm/$activateCode 时,我应该得到谢谢,您的帐户现在处于活动状态,您可以登录!并使用 else 语句
我在想应该改一下,开发一个新的模型函数来检查userActive是否已经设置为1,然后再显示另一个$message,这样就只能使用链接了。
查看:
<div class = "messages">
<?php if($confirmMessage != ''): ?>
<?php if($confirmError): ?>
<p class="error">
<?php echo $confirmMessage; ?>
</p>
<?php else: ?>
<p class="message">
<?php $confirmMessage?>
</p>
<?php endif; ?>
<?php endif; ?>
</div>
控制器:
function confirm(){
$activateCode = $this->uri->segment(3);
$error = FALSE;
$message = '';
if($activateCode == '')
{
$error = TRUE;
$message = 'Sorry you did not have a correct Activation Code.';
}
$userConfirmed = $this->users_model->confirm_user($activateCode);
if($userConfirmed){
$message = 'Thanks your account is now active you may login!';
}else{
$error = TRUE;
$message = 'I am sorry we do not have any details with that Activation Code';
}
$data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
$data['pageTitle'] = "User Confirm";
$data['confirmError'] = $error;
$data['confirmMessage'] = $message;
$this->load->view('frontend/assets/header', $data);
$this->load->view('frontend/user_confirm', $data);
$this->load->view('frontend/assets/footer');
}
我不确定为什么我没有收到验证消息,我只是了解我的观点。数据库正在更新到 1。
查看:
<h1><?php echo $companyName; echo nbs(1);?> - <?php echo $pageTitle; ?></h1>
<p>Error: <?php echo validation_errors();?></p>
控制器:
function confirm(){
$activateCode = $this->uri->segment(3);
if($activateCode == '')
{
$this->form_validation->set_message('userConfirmError', 'Sorry you did not have a correct Activation Code.');
}
$userConfirmed = $this->users_model->confirm_user($activateCode);
if($userConfirmed){
$this->form_validation->set_message('userConfirmed', 'Thanks your account is now active you may login!');
}else{
$this->form_validation->set_message('userRecord', 'I am sorry we do not have any details with that Activation Code');
}
$data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
$data['pageTitle'] = "User Confirm";
$this->load->view('frontend/assets/header', $data);
$this->load->view('frontend/user_confirm', $data);
$this->load->view('frontend/assets/footer');
}
确认功能:
function confirm_user($activateCode)
{
//Selects the userID where the given URI activateCode = ?
$this->db->select('userID');
$this->db->from('users');
$this->db->where('userActiveCode', $activateCode);
$result = $this->db->get();
if($result->num_rows == 1) // If the above result is = 1 then update the userActive row else it will fail
{
$this->db->set('userActive', 1);
$this->db->where('userActiveCode', $activateCode);
return TRUE;
}else{
return FALSE;
}
核心模型:
function companyDetails()
{
static $details;
if(!$details)
{
$this->db->select('coreCompanyName, coreContactName, coreContactEmail');
$details = $this->db->get('core')->first_row();
}
return $details;
}
【问题讨论】:
-
确定您是否在视图中回显了表单错误..?
-
@Sudhir 我已经包含了我的观点。
标签: php validation codeigniter