/** * Delete record with a specified id. If no ID is specified * then current record is deleted. * * @param mixed $id * * @return $this */ public function delete($id = null) { if ($id == $this->id) { $id = null; } return $this->atomic(function () use($id) { if ($id) { $c = clone $this; $c->load($id)->delete(); return $this; } elseif ($this->loaded()) { if ($this->hook('beforeDelete', [$this->id]) === false) { return $this; } $this->persistence->delete($this, $this->id); $this->hook('afterDelete', [$this->id]); $this->unload(); return $this; } else { throw new Exception(['No active record is set, unable to delete.']); } }); }
<?php require "class/Persistence.php"; //Populate database on first run $pers = new Persistence(); $pers->populateDatabase(); if (isset($_POST["fName"]) && isset($_POST["lName"])) { if (!empty($_POST["fName"]) && !empty($_POST["lName"])) { $pers->save($_POST["fName"], $_POST["lName"]); } } if (isset($_POST["btnRemove"])) { $pers->delete($_POST["btnRemove"]); } ?> <!DOCTYPE html> <!-- *File: index.php * *Copyright (c) 2015 Marcos Macedo <*****@*****.**> *Developed for client at Upwork.com *For usage permissions of this file please contact at marcos@softdev.science or the corresponding copyright holder. --> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="css/bootstrap.min.css" <script src="js/bootstrap.min.js" type="text/javascript"></script> <title>Name Directory</title>