public function index() { $news_collection = new NewsCollection(); $news = $news_collection->get($_GET['id']); $news_comment_collection = new NewsCommentCollection($_GET['id']); $comment = $news_comment_collection->get_all(); $this->loadView('website/article', array('news' => $news, 'comment' => $comment)); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_POST['name'] && $_POST['comment'] != '') { $comment = new NewsCommentEntity(); $comment->setName($_POST['name']); $comment->setContent($_POST['comment']); $comment->setNewsId($_GET['id']); $comment->setDate(date('Y-m-d H:i:s')); $news_comment_collection->save($comment); } } }
<?php require_once '../common/bootstrap.php'; $news_collection = new NewsCollection(); $article = $news_collection->get($_GET['id']); $news_comment_collection = new NewsCommentCollection($_GET['id']); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_POST['name'] != '' && $_POST['comment'] != '') { $comment = new NewsComment(); $comment->setName($_POST['name']); $comment->setContent($_POST['comment']); $news_comment_collection->save($comment); } } $comment = $news_comment_collection->get_all(); require_once 'includes/header.php'; ?> <article class="container-news"> <h2><?php echo $article->getTitle(); ?> </h2> <em>posted on <?php echo $article->getDate(); ?> by <?php echo $article->getAuthor(); ?> </em> <section> <img src="../storage/image1 laptop.png">
public function comment_delete() { $ncc = new NewsCommentCollection($_GET['news_id']); $ncc->delete($_GET['id']); header('Location: index.php?controller=news&action=comments&id=' . $_GET['news_id']); }