Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function index_get() {
- // Users from a data store e.g. database
- $id = $this->get('id');
- // If the id parameter doesn't exist return all the users
- if ($id === NULL)
- {
- $users = $this->db->get("list_dokter")->result_array();
- // Check if the users data store contains users (in case the database result returns NULL)
- if ($users)
- {
- // Set the response and exit
- $this->response($users, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
- }
- else
- {
- // Set the response and exit
- $this->response([
- 'status' => FALSE,
- 'message' => 'No users were found'
- ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
- }
- }
- // Find and return a single record for a particular user.
- else {
- $id = (int) $id;
- // Validate the id.
- if ($id <= 0)
- {
- // Invalid id, set the response and exit.
- $this->response(NULL, REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
- }
- // Get the user from the array, using the id as key for retrieval.
- // Usually a model is to be used for this.
- $this->db->where(array("id_dokter" => $id));
- $users = $this->db->get("list_dokter") -> row_array();
- $this->response($users, REST_Controller::HTTP_OK);
- }
- // $id = $this->get('id_Dokter');
- // if ($id == '') {
- // $data = $this->db->get('list_dokter')->result();
- // } else {
- // $this->db->where('id_Dokter', $id);
- // $data = $this->db->get('list_dokter')->result();
- // }
- // $this->response($data, 200);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement