2017-12-31 15 views
1

Ich möchte wissen, wie Online-Benutzerstatus zu ändern, wenn der Benutzer sich anmeldet. Ich habe danach gesucht, aber es gibt keine Antwort auf meine Frage. Ich bin neu beim Lernen dieses Codeigniters. Ich wünschte, ihr könnt mir bitte für mein Problem helfen.Online-Benutzerstatus auf Codeigniter

Controller:

public function signdevice() { 
    $device = $this->input->post('device'); 
    $pass = $this->input->post('password'); 
    $data = array(
     'device' => $device, 
     'password' => $pass, 
     'status' => $status 
    ); 
    $status = 1; 
    $res = $this->db->get_where('devices', $data); 
    if ($res->num_rows() > 0) { 
     $this->session->set_userdata(
      array(
       'signin' => TRUE, 
       'device' => $device, 
       'status' => $status 
      ) 
     ); 
     $data = array('device' => $device, 'password' => $pass, 'status' => 1); 
     $this->db->where('device', '$device'); 
     $this->db->update('devices', $data); 
     redirect(base_url('pelanggan')); 
    } else { 
     $this->session->set_flashdata('result_login', 'Wrong Username or Password.'); 
     redirect(base_url()); 
    } 
} 

Modelle:

function login($user,$pass) 
{ 
    $this->db->where('device', $user); 
    $this->db->where('password', $pass); 
    $query = $this->db->get('devices'); 
    if($query->num_rows()==1) { 
     return $query->row_array(); 
    } else { 
     $this->session->set_flashdata('error', 'Username atau password salah!'); 
     redirect('login'); 
    } 
} 

function update($id,$stat) 
{ 
    $data['status'] = $stat; 
    $stat = 1; 
    $this->db->where('kd_device', $id); 
    $this->db->update('devices', $stat); 
    return TRUE; 
} 
+0

Abgesehen von nicht speziell $ status = 0 initialisiert, was Sie haben sollte funktionieren? Was ist das eigentliche Problem, das Sie mit Ihrem Code haben? Was lässt dich denken, dass es nicht funktioniert. – TimBrownlaw

Antwort

2

Sie haben mehrere Linie & fehl am Platze Code fehlt.

Controller:

public function signdevice() { 
    $device = $this->input->post('device'); 
    $pass = $this->input->post('password'); 
    $data = array(
     'device' => $device, 
     'password' => $pass, 
     'status' => 0 // changed value to 0 
    ); 
    $status = 1; 
    $res = $this->db->get_where('devices', $data); 
    if ($res->num_rows() > 0) { 
     $this->session->set_userdata(
      array(
       'signin' => TRUE, 
       'device' => $device, 
       'status' => $status 
      ) 
     ); 
     $data = array('device' => $device, 'password' => $pass, 'status' => 1); 
     $this->db->where('device', $device); // removed quotes 
     $this->db->update('devices', $data); 
     redirect(base_url('pelanggan')); 
    } else { 
     $this->session->set_flashdata('result_login', 'Wrong Username or Password.'); 
     redirect(base_url()); 
    } 
} 

Modell:

... 
function update($id,$stat) 
{ 
    $stat = 1; // swapped this line with below 
    $data['status'] = $stat; // swapped this line with above 
    $this->db->where('kd_device', $id); 
    $this->db->update('devices', $data); // maybe what you want to save is $data? 
    return TRUE; 
} 
+0

Lustig ist, das Modell mit update() wird nie benutzt. – TimBrownlaw

+0

Du hast recht, beachte das auch :) –

+0

Danke Leute, es hat funktioniert: D –