예제 #1
0
파일: index.php 프로젝트: benjaminovak/ep
         http_response_code(201);
         header("Location: http://{$server_addr}" . "{$script_uri}/izdelki/{$id}");
     } catch (Exception $exc) {
         echo returnError(400, $exc->getMessage());
     }
 } else {
     if ($http_method == "PUT" && $param != null) {
         // update
         $inputParams = null;
         parse_str(file_get_contents("php://input"), $inputParams);
         $filteredInput = filter_var_array($inputParams, $rules);
         $filteredInput["id"] = $param;
         $product = array_filter($filteredInput);
         //var_dump($product);
         try {
             ProductsDB::update($product);
             http_response_code(204);
             // vračamo prazen odgovor
         } catch (Exception $exc) {
             echo returnError(400, $exc->getMessage());
         }
     } else {
         if ($http_method == "DELETE" && $param != null) {
             try {
                 $product = ProductsDB::get(["id" => $param]);
                 if ($product != null) {
                     ProductsDB::delete(["id" => $param]);
                     http_response_code(204);
                 } else {
                     returnError(404, "No book with id {$param}");
                 }