예제 #1
0
        $user = $db->users()->where('id', $id);
        if ($user->fetch()) {
            $result = $user->delete();
            echo json_encode(array("status" => true, "message" => "User deleted successfully"));
        } else {
            echo json_encode(array("status" => false, "message" => "User id {$id} does not exist"));
        }
    } catch (Exception $e) {
        echo $e->getMessage();
    }
});
/* Get tasks */
$app->get('/tasks', function () use($app, $db) {
    try {
        $tasks = array();
        foreach ($db->tasks() as $task) {
            $tasks[] = array('id' => $task['id'], 'title' => $task['title'], 'description' => $task['description'], 'start' => $task['start'], 'end' => $task['end']);
        }
        $app->response()->header('Content-Type', 'application/json');
        echo json_encode($tasks);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
});
/* Task Insert */
$app->post('/task', function () use($app, $db) {
    try {
        $app->response()->header('Content-Type', 'application/json');
        $task = $app->request()->post();
        $result = $db->tasks->insert($task);
        echo json_encode(array("id" => $result["id"], "message" => "Add task successfully"));