我有一个登录功能在我的控制器之前被调用,但我做了一些更改,它都停止了。codeigniter - jQuery的登录函数不调用/返回
我有2个输入用户名/密码和一个基本的登录信息提交
//使用Javascript
//控制器
class CMS extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->library('session');
//$this->_check_if_logged_in();
}
private function _check_if_logged_in() {
if (!$this->uri->segment(2) || $this->uri->segment(2) == 'login') return FALSE;
if ($this->session->userdata('logged_in') != TRUE) redirect('/cms');
}
public function index() {
if ($this->session->userdata('logged_in') == TRUE) redirect('/cms/home', 'refresh');
$this->load->view('cms/log_in_view');
$this->load->view('cms/parts/footer');
}
function login() {
echo json_encode(array('test' => 'test'))//doesn't get echoed
$data['user_name'] = $this->input->post('user');
$data['pass_word'] = sha1($this->input->post('password'));
$this->db->select('id');
$res = $this->db->get_where('login',$data,1)->row_array();
if (is_numeric($res['id'])) {
$data['logged_in'] = TRUE;
$this->session->set_userdata('logged_in',TRUE);
}
echo json_encode($res);
}
}
基本上我注释掉一切,我认为可能会阻碍回复,但这与我所学到的一切背道而驰。
我相信在控制器的登录功能不被调用,即使它没有之前的时候我并没有改变在js任何东西,或登录功能本身
显然没有你的第一个答案是正确的。没有找到$ res ['id'],所以最终会破坏整个功能。谢谢 –