iNoobAvicena

API index_get

Dec 4th, 2021
647
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function index_get() {
  2.         // Users from a data store e.g. database
  3.  
  4.         $id = $this->get('id');
  5.  
  6.         // If the id parameter doesn't exist return all the users
  7.  
  8.         if ($id === NULL)
  9.         {
  10.  
  11.             $users = $this->db->get("list_dokter")->result_array();
  12.  
  13.             // Check if the users data store contains users (in case the database result returns NULL)
  14.             if ($users)
  15.             {
  16.                 // Set the response and exit
  17.                 $this->response($users, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
  18.             }
  19.             else
  20.             {
  21.                 // Set the response and exit
  22.                 $this->response([
  23.                     'status' => FALSE,
  24.                     'message' => 'No users were found'
  25.                 ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
  26.             }
  27.         }
  28.  
  29.         // Find and return a single record for a particular user.
  30.         else {
  31.             $id = (int) $id;
  32.  
  33.             // Validate the id.
  34.             if ($id <= 0)
  35.             {
  36.                 // Invalid id, set the response and exit.
  37.                 $this->response(NULL, REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
  38.             }
  39.  
  40.             // Get the user from the array, using the id as key for retrieval.
  41.             // Usually a model is to be used for this.
  42.  
  43.             $this->db->where(array("id_dokter" => $id));
  44.             $users = $this->db->get("list_dokter") -> row_array();
  45.  
  46.             $this->response($users, REST_Controller::HTTP_OK);
  47.         }
  48.  
  49.         // $id = $this->get('id_Dokter');
  50.        
  51.         // if ($id == '') {
  52.  
  53.         //     $data = $this->db->get('list_dokter')->result();
  54.  
  55.         // } else {
  56.  
  57.         //     $this->db->where('id_Dokter', $id);
  58.  
  59.         //     $data = $this->db->get('list_dokter')->result();
  60.  
  61.         // }
  62.  
  63.         // $this->response($data, 200);
  64.  
  65.     }
RAW Paste Data