Пример #1
0
 public function insert($request)
 {
     $topic = $this->_em->getRepository('BlogBundle:Topic')->findOneById($request->get('topic_id'));
     $post = new Post();
     $post->setTitle($request->get('post')['title']);
     $post->setText($request->get('post')['text']);
     $post->setTopic($topic);
     $this->save($post);
 }
Пример #2
0
 public function createPostAction(Request $request)
 {
     $db = $this->getDoctrine()->getManager();
     $topic = $db->getRepository('BlogBundle:Topic')->findOneById($request->get('topic_id'));
     if (!$topic) {
         return $this->redirect($this->generateUrl('topic'));
     }
     $post = new Post();
     $post->setTitle($request->get('title'));
     $post->setText($request->get('text'));
     $post->setTopic($topic);
     $db->getRepository('BlogBundle:Post')->save($post);
     return $this->redirect($this->generateUrl('post', array('topic_id' => $topic->getId())));
 }