如何将注册表重定向到codeigniter上的另一个页面

问题描述:

当用户提交注册表单时,如何重定向到成功页面,问题是当我提交表单时,它将重定向到成功视图,但页面显示404没有找到。我的代码有问题吗?如何将注册表重定向到codeigniter上的另一个页面

公共函数注册(){

$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'); 

    } 
} 
+0

redirect(base_url()。'Controller/function'); –

使用本

redirect('controller/function'); 
+0

请为您的代码片段提供一些上下文。特别是,目前还不清楚OP如何将他的代码片段添加到他的代码中。 –

使用redirect()

redirect(base_url().'Controller/function name'); 
+0

请为您的代码片段提供一些上下文。特别是,目前还不清楚OP如何将他的代码片段添加到他的代码中。 –

请检查我的变化

$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'); 

} 
}