예제 #1
0
 /**
  * Creates a new Post entity.
  *
  * @Route("/post/new", name="admin_post_new")
  * @Method({"GET", "POST"})
  *
  * NOTE: the Method annotation is optional, but it's a recommended practice
  * to constraint the HTTP methods each controller responds to (by default
  * it responds to all methods).
  */
 public function newAction(Request $request)
 {
     $post = new Post();
     $post->setAuthorEmail($this->getUser()->getEmail());
     $form = $this->createForm(new PostType(), $post);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $post->setSlug($this->get('slugger')->slugify($post->getTitle()));
         $em = $this->getDoctrine()->getManager();
         $em->persist($post);
         $em->flush();
         return $this->redirectToRoute('admin_post_index');
     }
     return $this->render('admin/blog/new.html.twig', array('post' => $post, 'form' => $form->createView()));
 }
예제 #2
0
 private function loadPosts(ObjectManager $manager)
 {
     foreach (range(1, 10) as $i) {
         $post = new Post();
         $post->setTitle($this->getRandomPostTitle());
         $post->setSummary($this->getRandomPostSummary());
         $post->setSlug($this->container->get('slugger')->slugify($post->getTitle()));
         $post->setContent($this->getPostContent());
         $post->setAuthorEmail('*****@*****.**');
         $post->setPublishedAt(new \DateTime('now - ' . $i . 'days'));
         foreach (range(1, 5) as $j) {
             $comment = new Comment();
             $comment->setAuthorEmail('*****@*****.**');
             $comment->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds'));
             $comment->setContent($this->getRandomCommentContent());
             $comment->setPost($post);
             $manager->persist($comment);
             $post->addComment($comment);
         }
         $manager->persist($post);
     }
     $manager->flush();
 }
 /**
  * {@inheritDoc}
  */
 public function setAuthorEmail($authorEmail)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setAuthorEmail', array($authorEmail));
     return parent::setAuthorEmail($authorEmail);
 }