예제 #1
0


/* ---------------------------------------------------------------------------- */
// RESTful : keep it chill
/* ---------------------------------------------------------------------------- */

/* ---------------------------------------- */ 
// Songs
/* ---------------------------------------- */ 
/* ~  Get all songs ~ */
/* ~ set up GET route ~*/
$app->get('songs', function() use($app, $db, $pdo){
//    echo
    $songs = array();
    foreach ($db->songs() as $song) {
        $songs[]  = array(
            'id' => $song['id'],
            'title' => $song['title']
        );
    }
    $app->response()->header("Content-Type", "application/json");
    echo json_encode($songs, JSON_FORCE_OBJECT);
});

/* ~  Get a single song ~ */
$app->get('/songs/:id', function($id) use ($app, $db, $pdo) {
    $app->response()->header("Content-Type", "application/json");
    $song = $db->songs()->where('id', $id);
    if($data = $song->fetch()){
        echo json_encode(array(