Exemplo n.º 1
0
 /**
  * Action to view a given post
  * 
  * This action should only be called via GET
  * 
  * The expected HTTP parameters are:
  * <ul>
  * <li>id: Id of the post (via HTTP GET)</li>   
  * </ul>
  * 
  * The views are:
  * <ul>
  * <li>posts/view: If post is successfully loaded (via include).  Includes these view variables:</li>
  * <ul>
  *  <li>post: The current Post retrieved</li>
  *  <li>comment: The current Comment instance, empty or 
  *  being added (but not validated)</li>
  * </ul>
  * </ul>
  * 
  * @throws Exception If no such post of the given id is found
  * @return void
  * 
  */
 public function view()
 {
     if (!isset($_GET["id"])) {
         throw new Exception("id is mandatory");
     }
     $postid = $_GET["id"];
     // find the Post object in the database
     $post = $this->postMapper->findByIdWithComments($postid);
     if ($post == NULL) {
         throw new Exception("no such post with id: " . $postid);
     }
     // put the Post object to the view
     $this->view->setVariable("post", $post);
     // check if comment is already on the view (for example as flash variable)
     // if not, put an empty Comment for the view
     $comment = $this->view->getVariable("comment");
     $this->view->setVariable("comment", $comment == NULL ? new Comment() : $comment);
     // render the view (/view/posts/view.php)
     $this->view->render("posts", "view");
 }