我目前的 URI 有问题
示例我有一个名为add
- users/add 的函数,如果我的输入表单有错误,它会在 users/add 页面上显示错误,但如果一切正常,它会返回用户页面并显示成功,但 uri 仍然存在 /用户/添加,我必须重新导航到用户页面。
更新:
添加:
$data['message'] = '<div class="alert alert-success"><strong>Thank You</strong> Your User Has Been Added</div>';
$this->session->set_userdata('message', $data['message']);
redirect(site_url('dashboard/users'));
用户:
$message = $this->session->userdata('message');
if($message === FALSE)
{
$message='';
}else{
$this->session->unset_userdata('message');
}
原来的:
控制器:
public function add()
{
$this->form_validation->set_rules('userFirstName','First Name', 'required|trim|max_length[99]|xss_clean');
$this->form_validation->set_rules('userLastName','Last Name', 'required|trim|max_length[99]|xss_clean');
$this->form_validation->set_rules('userEmail','E-Mail', 'required|valid_email|trim|max_length[99]|xss_clean|is_unique[users.email]');
$this->form_validation->set_rules('userPassword','Password', 'required|trim|max_length[99]|xss_clean');
if($this->form_validation->run() === TRUE)
{
$userData = array(
'fName' => $this->input->post('userFirstName', TRUE),
'lName' => $this->input->post('userLastName', TRUE),
'email' => $this->input->post('userEmail', TRUE),
'password' => sha1($this->input->post('userPassword', TRUE))
);
$this->db->escape($userData);
$this->user_model->addUser($userData);
$data['contentMangement'] = $this->options_model->systemOptions();
$data['pageTitle'] = 'Add User';
$data['message'] = '<div class="alert alert-success"><strong>Thank You</strong> Your User Has Been Added</div>';
$this->load->view('_assets/dashHeader', $data);
$this->load->view('dashboard/users', $data);
$this->load->view('_assets/footer');
}elseif($this->form_validation->run() === FALSE)
{
$data['contentMangement'] = $this->options_model->systemOptions();
$data['pageTitle'] = 'Add User';
$data['message'] = validation_errors('<div class="alert alert-error">', '</div>');
$this->load->view('_assets/dashHeader', $data);
$this->load->view('dashboard/addUser', $data);
$this->load->view('_assets/footer');
}
}