当用户
提交注册表时,我如何重定向到成功页面,问题是当我提交表单时,它会重定向到成功视图,但页面显示找不到 404。我的代码有问题吗?
公共函数注册(( {
$this->load->library('form_validation');
$this->form_validation->set_rules('fname','First Name','required');
$this->form_validation->set_rules('lname','Last Name','required');
$this->form_validation->set_rules('username','username','required');
$this->form_validation->set_rules('password','Password','required');
$this->form_validation->set_rules('cpassword','Confim Password','required|matches[password]');
if ($this->form_validation->run() ) {
$this->load->model('Registration');
$this->Registration->create(
['fname' => ucfirst($_POST['fname']),
'lname' => ucfirst($_POST['lname']),
'username' => ucfirst($_POST['username']),
'password' => md5($_POST['password'])]);
redirect('templates/rsuccess');
} else {
$view_data['page_title'] = 'Register first';
$view_data['errors'] = $this->form_validation->error_array();
$this->load->view('templates/header', $view_data);
$this->load->view('auth/registration');
$this->load->view('templates/footer');
}
}
请检查我的更改
$this->load->library('form_validation');
$this->form_validation->set_rules('fname','First Name','required');
$this->form_validation->set_rules('lname','Last Name','required');
$this->form_validation->set_rules('username','username','required');
$this->form_validation->set_rules('password','Password','required');
$this->form_validation->set_rules('cpassword','Confim Password','required|matches[password]');
if ($this->form_validation->run() ) {
$this->load->model('Registration');
$this->Registration->create(
['fname' => ucfirst($_POST['fname']),
'lname' => ucfirst($_POST['lname']),
'username' => ucfirst($_POST['username']),
'password' => md5($_POST['password'])]);
redirect(base_url().'templates/rsuccess', 'location', 301);
} else {
$view_data['page_title'] = 'Register first';
$view_data['errors'] = $this->form_validation->error_array();
$this->load->view('templates/header', $view_data);
$this->load->view('auth/registration');
$this->load->view('templates/footer');
}
}
使用这个
redirect('controller/function');
使用 redirect()
redirect(base_url().'Controller/function name');