/** * method Delete() * Delete a record */ function Delete($param) { try { // get the parameter $key $key = $param['key']; // open a transaction with database 'sample' TTransaction::open('sample'); // instantiates object Produtos $object = new Produtos($key); // deletes the object from the database $object->delete(); // close the transaction TTransaction::close(); // reload the listing $this->onReload($param); // shows the success message new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted')); } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
<?php include '../header.php'; require_once '../dados/Produtos.php'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!isset($_GET['id'])) { header("Id do produto não informado", true, 400); die; } $id = $_GET['id']; try { $produto = Produtos::find($id); if (!$produto) { header("Produto não encontrado", true, 404); die; } $r = Produtos::delete($id); if (!$r) { header("Não foi possível excluir o produto", true, 500); die; } echo json_encode($r); } catch (Exception $e) { header("Erro do servidor", true, 500); die; } } else { header("Formato de requisição HTTP inválida", true, 400); die; }