10. 'Delete post' feature
·
7 commits
to master
since this release
Implement the 'delete post' feature:
- add a new rule to the routes:
'/posts/delete' => BASE_PATH . '/controllers/posts/delete.php' - in
views\posts\read.php, add a 'delete' button that is only visible if the current user is identical to the post's user:
if($_SESSION['currentUser'] == $post->userId) - upon button click, show a dialog that asks: 'Do you really want to delete this post?'.
- in the dialog, implement a small
<form method="post" action="/posts/delete">with a hidden<input name="postId" type="hidden" value="<?= $post->id ?>">. - create the
controllers\posts\delete.phpcontroller and insert this code:
$postId = $_POST['postId'];
unset($GLOBALS['posts'][$postId]);
saveData('posts');
header("location: /posts");