Beispiel #1
0
                $newEntry->timeStamp = $input['TimeStamp'];
                $this->dbContext->entries->add($newEntry);
                break;
            case 'PUT':
                //Put request: extract posted data from request body, parse it into an array,
                //extrat values from array and make the new entity entry,
                //Aslo take the id of entry to edit from query string
                //update the old entry with new one
                $newEntry = new Entry();
                $inputJSON = file_get_contents('php://input');
                $input = json_decode($inputJSON, TRUE);
                $newEntry->title = $input['Title'];
                $newEntry->text = $input['Text'];
                $newEntry->timeStamp = $input['TimeStamp'];
                $this->dbContext->entries->update($parameters['Id'], $newEntry);
                break;
            case 'Delete':
                //delete request: extract the id from queyr string, delete entry from database.
                $this->dbContext->entries->delete($parameters['Id']);
                break;
        }
        header('Content-Type: application/json');
        $result = json_encode($result);
        echo $result;
    }
}
//when theis page is requested, make a new controller object
//and execute the controller
$controller = new EntryController();
$controller->execute();