示例#1
0
<?php

require_once '../before.php';
use Entity\Comment;
if (isset($_GET['id'])) {
    $post = $entityManager->getRepository('Entity\\Post')->find($_GET['id']);
}
if (isset($_POST['submit'])) {
    $comment = new Comment();
    $comment->setMessage($_POST['message']);
    $comment->setAuthor($user);
    $comment->setPost($post);
    $entityManager->persist($comment);
    $entityManager->flush($comment);
}
$comments = $entityManager->getRepository('Entity\\Comment')->findBy(array('post' => $post), array('date' => 'ASC'));
?>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Les commentaires</title>
    </head>
    <body>
        <h1><?php 
echo $post->getSubject();
?>
</h1>
        <p>
            <?php 
示例#2
0
            header('Location: showthread.php?id=' . $_GET['tid']);
        }
    } else {
        $_SESSION['error'] = "Invalid action.";
        header('Location: threads.php');
    }
} else {
    if (!empty($_POST)) {
        if ($_POST['action'] == "addcomment") {
            $post = $em->find('Entity\\Post', intval($_POST['comment_tid']));
            $comment = new Comment();
            $comment->setMessage($_POST['comment_message']);
            $comment->setPost($post);
            $comment->setDate(new DateTime());
            if ($userLoggedIn) {
                $comment->setAuthor($user);
            } else {
                $anon = $em->getRepository('Entity\\User')->find(1);
                $comment->setAuthor($anon);
            }
            $em->persist($comment);
            $em->flush();
            $_SESSION['success'] = "Comment added.";
            header('Location: showthread.php?id=' . $_POST['comment_tid']);
        } else {
            $_SESSION['error'] = "Invalid action.";
            header('Location: threads.php');
        }
    } else {
        $_SESSION['error'] = "Could not process request.";
        header('Location: threads.php');