我使用POST方法创建了登录API,但它给了我错误 GET方法很有效。
控制器Api的student_login方法代码
类Api扩展了CI_Controller {
公共职能student_login() {
$username=$this->input->post['vUserName'];
$password=$this->input->post['vPassword'];
$this->load->model('Api_model');
$result=$this->Api_model->get_login($username,$password);
if(!empty($result))
{
$response["error"]="true";
$response["message"]="You have been successfully login";
echo json_encode(array('result'=>$result));
die( json_encode($response));
}
else
{
$response["error"]="false";
$response["message"]="Invalid Username and Password";
die(json_encode($response));
}
}
}
模型:加载表tbl_students
的数据类Api_model扩展了CI_Model { public function get_login($ name,$ pass) { // echo $ name,$ pass; $这 - > DB->选择( 'iStudentID,类,部,vDivision,vGrno'); $这 - > DB-肽从( 'tbl_students');
$this->db->where('vUserName',$name);
$this->db->where('vPassword',$pass);
//$this->db->from('tbl_students');
return $this->db->get()->result_array();
}
}