Controller:-
public function login($email, $password)
{
$table="test_api"/span>;
$email='[email protected]'。
$password='123456'。
$result = $this->Webservice_model-> login($email,$password) 。
$data[]=$result;
if($result){
$json = array("result"/span>=> $data, "status"=>1, "msg"=>"登錄成功! ")。)
}else{
$json = array("result"/span>=> $data, "status"=>0, "msg"=>"登錄失敗了! ")。)
}
header('Content-type: application/json')。
echo json_encode($json)。
}
模型:-
public function login($email, $password)
{
$this->db->where('email'/span>,$email)。
$this->db->where('password',$password)。
$query = $this->db->get('test_api')。
if($query->num_rows() == 1)
{
return $query->row()。
}
else[/span
{
return false;
}
當我使用這個路徑時,它沒有給我結果。
Webservice/[email protected]&password=123456。
uj5u.com熱心網友回復:
你可以通過使用CI_input獲得查詢字串:
public function login()
{
$email = $this->input->get('email')。
$password = $this->input->get('password);
$result = $this->Webservice_model->login($email, $password)。
$data[] = $result;
if($result) {
$json = array("result"/span> => $data, "status" => 1, "msg" => "登錄成功! ")。)
} else {
$json = array("result" => $data, "status" => 0, "msg" => "登錄失敗! ")。)
}
header('Content-type: application/json')。
echo json_encode($json)。
}
uj5u.com熱心網友回復:
由于你使用的是Codeigniter 3,你可以看一下這個方法。有了這個方法,你可以在控制器中呼叫查詢,也可以進行API頭的設定。這在Codeigniter 4中是不適用的。
。public function login() /span>{
header('Access-Control-Allow-Origin: *'/span>)。
header("Access-Control-Allow-Credentials: true")。
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS')。)
header('Access-Control-Max-Age: 1000')。
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token , Authorization')。)
$email= $this->input->post('email')。
$password = $this->input->post('password') 。
$this->db->select('email,password')。
$this->db->from('test_api')。
$this->db->where('email', $email) 。
$this->db->where('password', md5($password) )。)
$query = $this-> db->get();
$result = $query->row()。
if ($result != null) {
echo json_encode($result) 。
} else {
echo json_encode('false') 。
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/311013.html
標籤:
