public static function listTasks() { $db = ConnectionFactory::getDB(); $tasks = array(); foreach ($db->tasks() as $task) { //vai para o banco de dados dentro da tabela tasks $tasks[] = array('id' => $task['id'], 'description' => $task['description'], 'done' => $task['done']); } }
public static function delete($id) { $db = ConnectionFactory::getDB(); $task = $db->tasks[$id]; if ($task) { $task->delete(); return true; } return false; }
public static function delete($id) { $db = ConnectionFactory::getDB(); $guest = $db->guests[$id]; if ($guest) { $guest->delete(); return true; } return false; }
public static function delete($id) { $db = ConnectionFactory::getDB(); $cart = $db->carts[$id]; if ($cart) { $cart->delete(); return true; } return false; }
public static function delete($id) { $db = ConnectionFactory::getDB(); $item = $db->items[$id]; if ($item) { $item->delete(); return true; } return false; }
public static function update($updatedGuest) { $db = ConnectionFactory::getDB(); $guest = $db->guests[$updatedGuest['id']]; if ($guest) { $guest['nome'] = $updatedGuest['nome']; $guest['email'] = $updatedGuest['email']; return true; } return false; }
public static function listTasks() { $db = ConnectionFactory::getDB(); //Classe que pega a conexão com o Banco de Dados $tasks = array(); //$tasks = uma caixa, 'vetor', vazio foreach ($db->tasks() as $task) { //O tasks (depois do '$db->') é o nome da TABELA em schema.sql | Para cada registro da tabela, colocar dentro do $tasks (vetor) $tasks[] = array('id' => $task['id'], 'description' => $task['description'], 'done' => $task['done']); } $tasks; }
$app = new \Slim\Slim(); $app->get('/guest', function () use($app) { $db = ConnectionFactory::getDB(); $guests = array(); foreach ($db->guests() as $guests) { $guests[] = array('id' => $guest["id"], 'name' => $guest['name'], 'email' => $guest['email']); } $app->response()->header('Content-Type', 'application/json'); echo json_encode($guests); }); $app->post('/guest', function () use($app) { $db = ConnectionFactory::getDB(); $guestToAdd = json_decode($app->request->getBody(), true); $guest = $db->guests->insert($guestToAdd); $app->response->header('Content-Type', 'application/json'); echo json_encode($guest); }); $app->delete('/guest/:nome', function ($nome) use($app) { $db = ConnectionFactory::getDB(); $response = ""; $guest = $db->guests()->where('nome', $nome); if ($guest->fetch()) { $result = $guest->delete(); $response = array('status' => 'true', 'message' => 'Guest deleted!'); } else { $response = array('status' => 'false', 'message' => 'Guest with $id does not exit'); $app->response->setStatus(404); } $app->response()->header('Content-Type', 'application/json'); echo json_encode($response); });