public static function getMerchandiseByGetId() { $id = null; try { $id = self::getUrlParam('item_id'); } catch (Exception $ex) { throw new NotFoundException('No merchandise identifier provided.'); } if (!is_numeric($id)) { throw new NotFoundException('Invalid merchandise identifier provided.'); } $dao = new MerchandiseDao(); $merchandise = $dao->findById($id); if ($merchandise === null) { throw new NotFoundException('Unknown merchandise identifier provided.'); } return $merchandise; }
<?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();