コード例 #1
0
ファイル: index.php プロジェクト: star-fu-tv/dreamstatepoetry
    }
});

/* ~  Create new song with POST ~ */
// e.g. year=1981&make=DeLorean&model=DMC-12 //
$app->post('/fragment', function() use($app, $db, $pdo){
    $app->response()->header("Content-Type", "application/json");
    $fragment = $app->request()->post();
    $result = $db->fragments->insert($fragment);
    echo json_encode(array('id' => $result['id']));
});

/* ~ Update a song ~ */
$app->put('/fragment/:id', function($id) use($app, $db, $pdo){
    $app->response()->header("Content-Type", "application/json");
    $song = $db->fragment()->where("id", $id);
    if ($fragment->fetch()) {
        $post = $app->request()->put();
        $result = $fragment->update($post);
        echo json_encode(array(
            "status" => (bool)$result,
            "message" => "Fragment updated successfully"
            ));
    }
    else{
        echo json_encode(array(
            "status" => false,
            "message" => "Fragment id $id does not exist"
        ));
    }
});