コード例 #1
0
ファイル: RubroController.php プロジェクト: aalabarce/napoli
 /**
  * API Method inserts a new Rubro record and render response as JSON
  */
 public function Create()
 {
     try {
         $json = json_decode(RequestUtil::GetBody());
         if (!$json) {
             throw new Exception('The request body does not contain valid JSON');
         }
         $rubro = new Rubro($this->Phreezer);
         // TODO: any fields that should not be inserted by the user should be commented out
         // this is an auto-increment.  uncomment if updating is allowed
         // $rubro->Id = $this->SafeGetVal($json, 'id');
         $rubro->Nombre = $this->SafeGetVal($json, 'nombre');
         $rubro->Validate();
         $errors = $rubro->GetValidationErrors();
         if (count($errors) > 0) {
             $this->RenderErrorJSON('Please check the form for errors', $errors);
         } else {
             $rubro->Save();
             $this->RenderJSON($rubro, $this->JSONPCallback(), true, $this->SimpleObjectParams());
         }
     } catch (Exception $ex) {
         $this->RenderExceptionJSON($ex);
     }
 }