Example #1
0
 public function performGet($url, $arguments, $accept)
 {
     // Decode url
     UrlHelper::Decode($url, $model, $objectId);
     // Get Mapping
     $mapping = MappingHelper::GetMapping($model);
     if ($mapping != null) {
         $object = $mapping->DbTableName;
     } else {
         $object = $model;
     }
     // Read data from DB
     $dbReader = new DbReader();
     $dbReader->Open();
     $result = $dbReader->Read($object, $objectId);
     $dbReader->Close();
     if ($result == null) {
         // no data found
         Exceptions::NoDataException($object, $objectId);
     } else {
         $json = null;
         foreach ($result as $key => $row) {
             // Map names
             if ($mapping != null) {
                 $data = $mapping->MapDbToModel($row);
             } else {
                 $data = $row;
             }
             // Encode data using json
             if ($json != null) {
                 $json .= ",";
             }
             $json .= json_encode($data);
         }
         if (count($result) > 1) {
             $json = "[" . $json . "]";
         }
         // Write data to output
         header('Content-type: application/json; charset=utf-8');
         header('', true, HttpStatus::OK);
         echo utf8_encode($json);
     }
 }