We will modify the code of the Blog Dashboard once again to add a Delete link to each article displayed. Clicking on this link will display a JavaScript confirmation box, and clicking on Yes on that box will delete the article and reload the page:
1. Open up
dashboard.php
in your editor. Delete the old code in that file, and add the following code to it:<?php try{ $mongodb = new Mongo(); $articleCollection = $mongodb->myblogsite->articles; } catch (MongoConnectionException $e) { die('Failed to connect to MongoDB '.$e->getMessage()); } $currentPage = (isset($_GET['page'])) ? (int) $_GET['page'] : 1; $articlesPerPage = 5; //number of articles to show per page $skip = ($currentPage - 1) * $articlesPerPage; $cursor = $articleCollection->find(array(), $fields=array('title', 'saved_at')); $totalArticles = $cursor->count(); $totalPages = (int) ceil($totalArticles / $articlesPerPage); $cursor->sort(array('created_at' => -1))->skip...