public function findById($id) { $row = $this->query('SELECT comment_id, comment, item_id FROM comment WHERE comment_id = ' . (int) $id)->fetch(); if (!$row) { return null; } $comment = new Comment(); CommentMapper::map($comment, $row); return $comment; }
<?php $merchdao = new MerchandiseDao(); $dao = new CommentDao(); $item_id = Utils::getUrlParam('item_id'); $comment = new Comment(); $item = $merchdao->findById($item_id); if (array_key_exists('save', $_POST)) { $data = array('comment' => filter_var($_POST['comment']['comment'], FILTER_SANITIZE_STRING), 'username' => $_SESSION['username'], 'user_id' => $_SESSION['user_id'], 'item_id' => filter_var($_GET['item_id'], FILTER_SANITIZE_NUMBER_INT)); CommentMapper::map($comment, $data); $dao->save($comment); $comment->setComment(''); } $comment_list = $dao->find();