create allows location id

master
Matt Huntington 8 years ago
parent be03fafd0a
commit fae323eba8

@ -7,7 +7,7 @@ if($_REQUEST['action'] === 'index'){
} 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); $newPerson = new Person(null, $body->name, $body->age, $body->location_id);
$allPeople = People::create($newPerson); $allPeople = People::create($newPerson);

@ -1 +1 @@
INSERT INTO people (name, age) VALUES ($1, $2) INSERT INTO people (name, age, location_id) VALUES ($1, $2, $3)

@ -8,10 +8,13 @@ class Person {
public $id; public $id;
public $name; public $name;
public $age; public $age;
public function __construct($id, $name, $age) { public function __construct($id, $name, $age, $location_id = null) {
$this->id = $id; $this->id = $id;
$this->name = $name; $this->name = $name;
$this->age = $age; $this->age = $age;
if($location_id){
$this->location_id = $location_id;
}
} }
} }
@ -42,7 +45,7 @@ class People {
} }
static function create($person){ static function create($person){
$query = file_get_contents(__DIR__ . '/../database/sql/people/create.sql'); $query = file_get_contents(__DIR__ . '/../database/sql/people/create.sql');
$result = pg_query_params($query, array($person->name, $person->age)); $result = pg_query_params($query, array($person->name, $person->age, $person->location_id));
return self::find(); return self::find();
} }

Loading…
Cancel
Save