我正在使用Codeigniter 2.1.4,也是這個框架的新成員。當我試圖在控制器類上加載模型時,瀏覽器拋出錯誤ID 500。下面是模型類文件名代碼:在控制器類上加載模型時出現500錯誤
merchant_login.php
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Merchant_model extends MY_Model {
public $tbl_user = 'users';
function __construct(){
parent::__construct();
$this->load->database('merchant', TRUE, TRUE);
}
function user_login($data)
{
$this->db->from($this->tbl_user);
$this->db->where($data);
$query = $this->db->get();
if($query->num_rows()==1)
{
$this->db->select("CURRENT_LOGIN");
$this->db->from($this->tbl_user);
$this->db->where("USER_ID", $data["USER_ID"]);
$q = $this->db->get();
$res = $q->result();
$current_time = $res[0]->CURRENT_LOGIN;
$last_time = $current_time;
$current_time = date("Y-m-j H:i:s");
$arr = array(
"CURRENT_LOGIN" => $current_time,
"LAST_LOGIN" => $last_time,
"LAST_IP" => $this->input->ip_address()
);
$this->db->where("USER_ID", $data["USER_ID"]);
$this->db->update($this->tbl_user, $arr);
$this->db->from($this->tbl_user);
$this->db->where($data);
$query = $this->db->get();
return $query->row_array();
}
return false;
}
} ?>
這裏是控制器和文件名稱的代碼是:
「的login.php」
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Login extends MY_Controller {
function __construct() {
parent::__construct();
$this->load->library(array("form_validation", "session"));
}
//merchant section start
public function merchant_login() {
$this->session->keep_flashdata("return_url");
$this->form_validation->set_rules('loginName', 'Login', 'trim|valid_email|required');
$this->form_validation->set_rules('loginPassword', 'Password', 'trim|required');
if ($this->session->userdata("merchantLogged") != 1) {
if ($this->form_validation->run() == FALSE) {
$data["error"] = validation_errors();
header('Content-type: application/json');
echo json_encode($data);
} else {
$d['USER_ID'] = $this->input->post("loginName");
$d['USER_PASSWD'] = sha1($this->input->post("loginPassword"));
$this->load->model("merchant_model", "model", TRUE);
$user = $this->model->user_login($d);
if ($user) {
if ($this->input->post("security") == 'not') {
//Cal to a member function of the model class
if ($this->model->user_ip_check($d) == false) {
$this->session->set_userdata('u_id', $this->input->post("loginName"));
$this->session->set_userdata('u_pd', $this->input->post("loginPassword"));
$data['redirect'] = site_url("merchants/ip_security/");
} else {
$usr['type'] = "MR";
unset($user['USER_PASSWD']);
// unset($user['ID']);
unset($user['MM_NAME']);
//$this->load->database('default', TRUE, TRUE);
$this->session->set_userdata($usr);
$this->session->set_userdata($user);
$this->set_merchantLogged(1);
// if($this->session->flashdata("return_url")){
// $data['redirect'] = site_url("user/" . $this->session->flashdata("return_url"));
// }
// else{
$data['redirect'] = site_url("merchant/account");
// }
}
} else {
$d['que'] = $this->input->post("sec_q");
$d['ans'] = $this->input->post("sec_q_answer");
if ($this->model->check_que($d) == true) {
$this->session->unset_userdata('u_id');
$this->session->unset_userdata('u_pd');
$usr['type'] = "MR";
unset($user['USER_PASSWD']);
unset($user['MM_NAME']);
$this->session->set_userdata($usr);
$this->session->set_userdata($user);
$this->set_merchantLogged(1);
$data['redirect'] = site_url("merchant/account");
} else {
$data['redirect'] = site_url("merchants/ip_security");
}
}
} else {
$data["error"] = "Username or password are wrong";
$data["islogin"] = true;
}
header('Content-type: application/json');
echo json_encode($data);
}
} else {
if ($this->session->flashdata("return_url")) {
$data['redirect'] = site_url("merchant/" . $this->session->flashdata("return_url"));
} else {
$data['redirect'] = site_url("home");
}
header('Content-type: application/json');
echo json_encode($data);
}
}
}
?>
您正在使用AJAX? –
錯誤日誌中的任何內容? – Fracsi
請給我們看MY_Model.php謝謝。 – Kyslik