parent
d8459b7053
commit
e782e501c2
@ -1,26 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
include_once __DIR__ . '/../models/person.php';
|
include_once __DIR__ . '/../models/company.php';
|
||||||
|
|
||||||
if($_REQUEST['action'] === 'index'){
|
if($_REQUEST['action'] === 'index'){
|
||||||
echo json_encode(People::find());
|
echo json_encode(Companies::find());
|
||||||
} else if ($_REQUEST['action'] === 'post'){
|
} else if ($_REQUEST['action'] === 'post'){
|
||||||
$requestBody = file_get_contents('php://input');
|
$requestBody = file_get_contents('php://input');
|
||||||
$body = json_decode($requestBody);
|
$body = json_decode($requestBody);
|
||||||
$newPerson = new Person(null, $body->name, $body->age);
|
$newCompany = new Company(null, $body->name);
|
||||||
|
|
||||||
$allPeople = People::create($newPerson);
|
$allCompanies = Companies::create($newCompany);
|
||||||
|
|
||||||
echo json_encode($allPeople);
|
echo json_encode($allCompanies);
|
||||||
} else if ($_REQUEST['action'] === 'delete'){
|
} else if ($_REQUEST['action'] === 'delete'){
|
||||||
$allPeople = People::delete($_REQUEST['id']);
|
$allCompanies = Companies::delete($_REQUEST['id']);
|
||||||
echo json_encode($allPeople);
|
echo json_encode($allCompanies);
|
||||||
} else if ($_REQUEST['action'] === 'update'){
|
} else if ($_REQUEST['action'] === 'update'){
|
||||||
$requestBody = file_get_contents('php://input');
|
$requestBody = file_get_contents('php://input');
|
||||||
$body = json_decode($requestBody);
|
$body = json_decode($requestBody);
|
||||||
$updatedPerson = new Person(null, $body->name, $body->age);
|
$updatedCompany = new Company(null, $body->name);
|
||||||
$allPeople = People::update($_REQUEST['id'], $updatedPerson);
|
$allCompanies = People::update($_REQUEST['id'], $updatedCompany);
|
||||||
|
|
||||||
echo json_encode($allPeople);
|
echo json_encode($allCompanies);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in new issue