public function comments() { $id = $this->uri->segment(3); $post = $this->em->getRepository('Entities\\Post')->find($id); if ($post === NULL) { throw new \Exception("Post not found!"); } $add = $this->input->post('comment'); if ($add == 'comment') { $body = $this->input->post('post-comment'); $comment = new Comment(); $comment->setBody($body); $comment->setPublicationDate(new \DateTime()); $comment->setPost($post); $this->em->persist($comment); $this->em->flush(); redirect('blog/comments/' . $post->getId(), 'refresh'); } $data['content'] = $this->load->view('blog\\comments', array('post' => $post), true); $this->load->view('main', $data); }
/** * Add comment * * @param \Entities\Comment $comment * * @return Post */ public function addComment(\Entities\Comment $comment) { $this->comments[] = $comment; $comment->setPost($this); return $this; }