Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. public function get_get()
  2.     {
  3.         // $sekolah_datas list ALL data sekolah
  4.         // $sekolah_data per satu sekolah
  5.  
  6.         $sekolah_datas = $this->model_gtech->get_daftar_sekolah();
  7.         $id = $this->get('id');
  8.  
  9.         if ($id === null) {
  10.             if ($sekolah_datas) {
  11.                 $this->response($sekolah_datas, 200);
  12.             }
  13.            
  14.             else {
  15.                 $this->response([
  16.                     'status' => false,
  17.                     'message' => 'No daftar sekolah were found'
  18.                 ], 404);
  19.             }
  20.         }
  21.  
  22.         $id = (int) $id;
  23.        
  24.         if ($id <= 0) {
  25.             $this->response(null, 400);
  26.         }
  27.  
  28.         $sekolah_data = null;
  29.  
  30.         if (!empty($sekolah_datas)) {
  31.             foreach ($sekolah_datas as $key => $value) {
  32.                 if (isset($value['id']) && $value['id'] == $id) {
  33.                     $sekolah_data = $value;
  34.                 }
  35.             }
  36.         }
  37.  
  38.         if (!empty($sekolah_data)) {
  39.             $this->set_response($sekolah_data, 200);
  40.         }
  41.        
  42.         else {
  43.             $this->set_response([
  44.                 'status' => false,
  45.                 'message' => 'Data sekolah could not be found'
  46.             ], 404);
  47.         }
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement