我有一个使用 CI 表单验证的登录表单。
表格位于 domain.com/login
它运行一个名为 validate_credentials 的函数,如果验证失败,它会重新加载视图。问题是 URL 继续显示:
domain.com/login/validate_credentials
如何删除 /validate_credentials?
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
public function index()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_error_delimiters('<div class="alert alert-error">', '</div><br />');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('login/login');
}
else
{
$this->load->view('clock/clock');
}
}
function validate_credentials() {
$this->load->model('membership_model');
$query = $this->membership_model->validate();
if($query) {// staff credentials validated...
$data = array(
'email' => $this->input->post('email'),
'staff_logged_in' => TRUE
);
$this->session->set_userdata($data);
redirect('clock/clock');
}
else { // not validated reload index function
$this->index();
}
}
}