成功注册后,如何在主页中显示成功消息(不是警告框)?
这是我的控制器功能。
public function reg()
{
$data['baseurl'] = base_url();
$baseurl = base_url();
$this->load->model('Regdatabase');
$this->form_validation->set_rules('firstname', 'First Name', 'required');
$this->form_validation->set_rules('lastname', 'Last Name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|matches[cpassword]|md5');
$userdata['id'] = Null;
$userdata['firstname'] = $this->input->post('firstname');
$userdata['lastname'] = $this->input->post('lastname');
$userdata['email'] = $this->input->post('email');
$userdata['password'] = $this->input->post('password');
$userdata['status'] = "1";
$this->Regdatabase->DataInsert($userdata);
// INSERT DATA INTO TABLE
redirect($baseurl.'register');
}
答案 0 :(得分:4)
在会话Flash消息中设置您的成功消息,然后根据需要显示在主页中。
$this->session->set_flashdata('success_msg', 'success');
获取成功消息
echo $this->session->flashdata('success_msg');
在控制器中设置Flash消息,然后在成功注册后重定向到主页。
答案 1 :(得分:1)
请参阅以下示例以获得清晰的想法..
function index()
{
$this->load->library('form_validation'); // Load validation library.
$this->load->model('register_model');
$data['msg']=NULL; // Declare msg as NULL.
// On form submit.
if(isset($_POST['add']))
{
// Input fields validations
$this->form_validation->set_rules('name', 'Name', 'trim|required|max_length[100]|min_length[3]');
if ($this->form_validation->run() === TRUE)
{
$name=$this->input->post('name');
$values=array('name' => $name);
$result=$this->register_model->my_insert($values,'users'); // Insert user into database.
if($result_id)
$data['msg']='1';
else
$data['msg']='2';
}
}
$this->load->view('register', $data);
}
答案 2 :(得分:1)
用于在codeigniter中显示成功消息的flash数据
$this->session->set_flashdata('item', 'value');
You can also pass an array to set_flashdata(), in the same manner as set_userdata().
To read a flashdata variable:
$this->session->flashdata('item');
http://ellislab.com/codeigniter%20/user-guide/libraries/sessions.html
答案 3 :(得分:0)
使用参数重定向到主页并显示成功消息。
redirect($baseurl.'home/index/success');
在家中获取参数并根据该信息显示消息。
$msg=$this->uri->segment(3);