From bdcdcea14b9f6af29e5fb812767ecbeea7d85189 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Wed, 20 Sep 2017 11:21:37 -0400 Subject: [PATCH] moved create to controller file --- .htaccess | 4 ++-- controllers/people.php | 8 ++++++++ post.php | 12 ------------ 3 files changed, 10 insertions(+), 14 deletions(-) delete mode 100644 post.php diff --git a/.htaccess b/.htaccess index a3ff53d..7010b0d 100644 --- a/.htaccess +++ b/.htaccess @@ -1,9 +1,9 @@ RewriteEngine On RewriteCond %{REQUEST_METHOD} ^GET$ RewriteRule ^people$ controllers/people.php?action=index +RewriteCond %{REQUEST_METHOD} ^POST$ +RewriteRule ^people$ controllers/people.php?action=post RewriteCond %{REQUEST_METHOD} ^DELETE$ RewriteRule ^people/([0-9]+)$ delete.php?id=$1 -RewriteCond %{REQUEST_METHOD} ^POST$ -RewriteRule ^people$ post.php RewriteCond %{REQUEST_METHOD} ^PUT$ RewriteRule ^people/([0-9]+)$ update.php?id=$1 diff --git a/controllers/people.php b/controllers/people.php index 45e04cd..919638c 100644 --- a/controllers/people.php +++ b/controllers/people.php @@ -3,6 +3,14 @@ include __DIR__ . '/../data/people.php'; if($_REQUEST['action'] === 'index'){ + echo json_encode($people); + } else if ($_REQUEST['action'] === 'post'){ + $requestBody = file_get_contents('php://input'); + $body = json_decode($requestBody); + $zagthar = new Person($body->name, $body->age); + + $people[] = $zagthar; + echo json_encode($people); } ?> diff --git a/post.php b/post.php deleted file mode 100644 index 425b649..0000000 --- a/post.php +++ /dev/null @@ -1,12 +0,0 @@ -name, $body->age); - - $people[] = $zagthar; - - echo json_encode($people); -?>