public function findPostById($id)
 {
     $stmt = $this->dtb->prepare('SELECT * FROM posts WHERE id = :id');
     $stmt->bindValue(':id', $id, PDO::PARAM_INT);
     $stmt->execute();
     $UM = new PdoUserManager();
     $CM = new PdoCommentManager();
     $d = $stmt->fetch(PDO::FETCH_OBJ);
     $data = new Post($d->id, $d->title, $d->body, $d->publicationDate, $UM->findUserById($d->userID), $CM->findAllCommentsForPostId($d->id));
     $stmt->closeCursor();
     return $data;
 }
Example #2
0
<?php

require_once __DIR__ . '/classes/manager/PdoCommentManager.class.php';
require_once __DIR__ . '/classes/entities/User.class.php';
session_start();
if (!isset($_SESSION['user'])) {
    header('Location: ./login.php');
} else {
    $CM = new PdoCommentManager();
    $CM->addComment($_POST['content'], $_GET['id'], $_SESSION['user']);
    echo json_encode(array('date' => date('d/m/Y H:i:s', time()), 'author' => $_SESSION['user']->firstname . ' ' . $_SESSION['user']->lastname, 'body' => $_POST['content']));
}