-
Notifications
You must be signed in to change notification settings - Fork 11
/
create.php
33 lines (28 loc) · 929 Bytes
/
create.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
// Headers
//RewriteRule ^create/task/([^/]*)$ /create.php?item=$1 [L]
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Allow-Headers: Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With');
include_once 'config/Database.php';
include_once 'models/Todo.php';
// Instantiate DB & connect
$database = new Database();
$db = $database->connect();
$output = array();
// Instantiate Todo object
$todo = new Todo($db);
// Get raw posted data
$data = json_decode(file_get_contents("php://input"));
$todo->item = $data->item;
// Create Task
if ($todo->create()) {
$output['status'] = 200;
$output['message'] = "Task Created";
} else {
$output['status'] = 204;
$output['message'] = "Task Not Created";
}
// Turn to JSON & output
echo json_encode($output);