Advertisement
sanca

controller

Dec 16th, 2013
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 KB | None | 0 0
  1. public function datatab($action='read'){
  2.          if (IS_AJAX) {
  3.                 $action = $this->request->post('action');
  4.                 switch ($action){
  5.                         default:
  6.                                 $this->read();
  7.                         break;
  8.                         case 'read':
  9.                                 $this->read();
  10.                         break;
  11.                         case 'create':
  12.                                 $this->create($this->request->post('data'));
  13.                         break;
  14.                         case 'edit':
  15.                                 $this->update($this->request->post('id'));
  16.                         break;
  17.                         case 'remove':
  18.                                 $this->delete($this->request->post('data'));
  19.                         break;
  20.                 }
  21.         }
  22.      }
  23.      
  24.      private function create($database){
  25.         $data = $this->rest->getRequest();
  26.         $data['requestMethod'] = $this->rest->requestMethod;
  27.         $this->datasiswa->tambah($database);
  28.         $this->outputJSON($data, 200);
  29.     }
  30.    
  31.     private function read(){    
  32.         $data = $this->rest->getRequest();
  33.         $data['requestMethod'] = $this->rest->requestMethod;
  34.         $data['aaData'] = $this->datasiswa->viewall();
  35.         $this->outputJSON($data, 200);
  36.     }
  37.    
  38.     private function update($id){
  39.         $data = $this->rest->getRequest();
  40.         $data['requestMethod'] = $this->rest->requestMethod;
  41.         $values= $this->request->post('data');
  42.         $where = array('id'=> $this->request->post('id',FILTER_SANITIZE_NUMBER_INT));
  43.         $this->datasiswa->edit($database,$where);
  44.         $this->outputJSON($data, 200);
  45.     }
  46.    
  47.     private function delete($where){
  48.         $data = $this->rest->getRequest();
  49.         $data['requestMethod'] = $this->rest->requestMethod;
  50.         $this->datasiswa->hapusbyid($where);
  51.         $this->outputJSON($data, 200);
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement