Beispiel #1
0
 /**
  * Display single page
  * @return [object] [Todo]
  */
 public function showAction()
 {
     $id = $this->dispatcher->getParam('id');
     $post = Posts::findFirstByid($id);
     if (!$post) {
         return $this->response->redirect("index");
     }
     $ipAddress = $this->request->getClientAddress();
     $viewed = PostsViews::count(array('postsId = ?0 AND ipaddress = ?1', 'bind' => array($id, $ipAddress)));
     //A view is stored by ipaddress
     if (!$viewed) {
         //Increase the number of views in the post
         $post->numberViews++;
         $postView = new PostsViews();
         //Update numberViews in table post ORM
         $postView->post = $post;
         $postView->ipaddress = $ipAddress;
         if (!$postView->save()) {
             foreach ($postView->getMessages() as $message) {
                 $this->flash->error($message);
             }
         }
     }
     $this->view->post = $post;
 }
Beispiel #2
0
 public function showAction()
 {
     $id = $this->dispatcher->getParam('id');
     $post = Posts::findFirstByid($id);
     if (!$post) {
         return $this->response->redirect("index");
     }
     $this->view->post = $post;
 }