Esempio n. 1
0
        echo json_encode($results);
    }
});
// PUT route
$app->put('/ingredients/:id', function ($id) use($app) {
    $request = (array) json_decode($app->request()->getBody());
    $name = $request['name'];
    $db = new Ingredients();
    $items = $db->update_ingredient($id, $name);
    if ($items) {
        // if successful, return the new object with the values
        $results = array('id' => $id, 'name' => $name);
        $app->response()->header('Content-Type', 'application/json');
        echo json_encode($results);
    } else {
        $app->response()->status(500);
    }
});
// DELETE route
$app->delete('/ingredients/:id', function ($id) use($app) {
    $request = (array) json_decode($app->request()->getBody());
    $db = new Ingredients();
    $items = $db->delete_ingredient($id);
    if ($items) {
        // if successful, just return the deleted item if it's needed on the client side
        $app->response()->header('Content-Type', 'application/json');
        echo json_encode($request);
    } else {
        $app->response()->status(500);
    }
});
Esempio n. 2
0
 function __construct()
 {
     echo 'adding ingredient Butter' . "\n";
     $this->setWeigth(5);
     parent::__construct();
 }
Esempio n. 3
0
$app->put('/recipes/:id', function ($id) use($app) {
    $request = (array) json_decode($app->request()->getBody());
    $name = $request['name'];
    $db = new Recipes();
    $items = $db->update_recipe($id, $name);
    if ($items) {
        // if successful, return the new object with the values
        $results = array('id' => $id, 'name' => $name);
        $app->response()->header('Content-Type', 'application/json');
        echo json_encode($results);
    } else {
        $app->response()->status(500);
    }
});
// DELETE route
$app->delete('/recipes/:id', function ($id) use($app) {
    $request = (array) json_decode($app->request()->getBody());
    $db = new Recipes();
    $items = $db->delete_recipe($id);
    if ($items) {
        $db = new Ingredients();
        $items = $db->delete_ingredient_by_value($id);
        $db = new Directions();
        $items = $db->delete_direction_by_value($id);
        // if successful, just return the deleted item if it's needed on the client side
        $app->response()->header('Content-Type', 'application/json');
        echo json_encode($request);
    } else {
        $app->response()->status(500);
    }
});