我正在使用 MY_Controller 来处理登录功能,问题是我不知道如何在 AJAX 请求发生时阻止 MY_Controller 被扩展。似乎 redirect() 将停止具有非 AJAX 请求的子类,是否可以停止为 AJAX 请求执行的子类?
function __construct() {
parent::__construct();
if(!$this->input->is_ajax_request()) {
if(!$this->session->userdata('userid')) {
//Render public menu in view
$this->load->view('header_public_view');
if($this->login_required()) {
//Possibly change to render authentication view rather than redirect
$this->session->set_userdata('destination', $this->input->server('REQUEST_URI'));
redirect('authentication/login');
}
}
else {
$this->load->model('user_model');
$data['user'] = $this->user_model->get_user($this->session->userdata('userid'));
$this->load->view('header_user_view', $data);
}
}
else {
if(!this->session->userdata('userid') && $this->login_required) {
//send response telling client to redirect
}
}
}