通过 php ci 设置快讯
flash message setting through php ci
我正在尝试向数据库中插入一个条目。首先,我检查电子邮件 ID 是否已注册。如果是,将显示一条消息,说明电子邮件 ID 已被使用,否则将数据插入数据库。
但是页面刷新后还是继续显示。我希望它随着页面刷新而消失。
public function register()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('email','email','required|is_unique[register.email]');
if($this->form_validation->run() == FALSE){
////////////problem is here ///////////////////////
$this->load->view('view/login_register');
$this->session->set_flashdata('message_error','This id is already taken');
}
else
{
///$username=$this->input->post('username');
$email=$this->input->post('email');
$data= array(
////'email'=>$this->input->post('email')
'email'=>$email,
//'password'=>$this->input->post('password'),
);
$last_id=$this->model->registeration($data);
if ($last_id>0) {
$this->send_email($email);
$this->session->set_flashdata('message', 'To complete registration, click the link in email we just send you at khadija@precisetech.com.pk');
redirect('controller/register');
}
}
if(error_flag == 1){
return false;
}else{
return true;
}
}
我还有别的办法。如下:
在控制器中:
if($this->form_validation->run() == FALSE){
$data['msg'] = '<div class="alert alert-dismissable alert-danger"><button class="close" data-dismiss="alert" type="button">×</button>This id is already taken.</div>';
$this->load->view('view/login_register', $data);
}
在视图中这样做:
<?php if(isset($msg)){echo $msg ;} ?>
我正在尝试向数据库中插入一个条目。首先,我检查电子邮件 ID 是否已注册。如果是,将显示一条消息,说明电子邮件 ID 已被使用,否则将数据插入数据库。
但是页面刷新后还是继续显示。我希望它随着页面刷新而消失。
public function register()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('email','email','required|is_unique[register.email]');
if($this->form_validation->run() == FALSE){
////////////problem is here ///////////////////////
$this->load->view('view/login_register');
$this->session->set_flashdata('message_error','This id is already taken');
}
else
{
///$username=$this->input->post('username');
$email=$this->input->post('email');
$data= array(
////'email'=>$this->input->post('email')
'email'=>$email,
//'password'=>$this->input->post('password'),
);
$last_id=$this->model->registeration($data);
if ($last_id>0) {
$this->send_email($email);
$this->session->set_flashdata('message', 'To complete registration, click the link in email we just send you at khadija@precisetech.com.pk');
redirect('controller/register');
}
}
if(error_flag == 1){
return false;
}else{
return true;
}
}
我还有别的办法。如下:
在控制器中:
if($this->form_validation->run() == FALSE){ $data['msg'] = '<div class="alert alert-dismissable alert-danger"><button class="close" data-dismiss="alert" type="button">×</button>This id is already taken.</div>'; $this->load->view('view/login_register', $data); }
在视图中这样做:
<?php if(isset($msg)){echo $msg ;} ?>