Example #1
0
 public function actionOne()
 {
     $id = $_GET['id'];
     // If a comment has been sent:
     if ($this->isPost()) {
         $comm = new ModelComment();
         // fields cannot be empty!
         $success = $comm->fill(['article_id' => $id, 'author' => htmlspecialchars($_POST['author']), 'text' => htmlspecialchars($_POST['text'])]);
         $success ? $comm->save() : ($_SESSION['error'] = 'Fill all fields!');
         header('Location: /article/one?id=' . $id . '#comment');
         exit;
     }
     // Getting the particular article:
     $item = ModelArticle::getOneById($id);
     $this->isFound($item);
     $comments = ModelComment::getByColumn('article_id', $id);
     $view = new View(['item' => $item, 'comments' => $comments, 'title' => $item->title]);
     $view->displayPage('articles/one');
 }