コード例 #1
0
ファイル: thread.php プロジェクト: beardorder/website
<?php

require_once 'classes/post.class.php';
require_once 'classes/thread.class.php';
require_once 'classes/user.class.php';
if (isset($_GET['id'])) {
    $thread = new thread($_GET['id']);
    $threadData = $thread->getData();
    $author = new user($threadData['userid']);
} else {
    header('Location: ?page=forums');
}
if (isset($_POST['submit'])) {
    $post = new post();
    $post->insert($_POST['text'], $_SESSION['userid'], $_GET['id']);
}
$posts = array();
try {
    $getPosts = $con->prepare('select id, text, userid, date from posts where threadid = :threadid');
    $getPosts->bindValue('threadid', $_GET['id'], PDO::PARAM_INT);
    $getPosts->execute();
} catch (PDOException $e) {
    die($config['errors']['database'] . $e->getMessage());
}
while ($post = $getPosts->fetch()) {
    $author = new user($post['userid']);
    $post['username'] = $author->getData()['name'];
    $posts[] = $post;
}
echo $twig->render('thread.html', array('thread' => $threadData, 'author' => $author->getData(), 'loggedin' => isset($_SESSION['userid']), 'posts' => $posts));