예제 #1
0
 private function loadPosts(ObjectManager $manager)
 {
     $joeywang = $this->getReference("joeywang");
     $angli = $this->getReference("angli");
     foreach (range(1, 30) as $i) {
         $post = new Post();
         $post->setTitle($this->getRandomPostTitle());
         $post->setNote($this->getNote());
         // 			$post->setSlug($this->container->get('slugger')->slugify($post->getTitle()));
         $post->setContent($this->getPostContent());
         if (rand(0, 1) == 0) {
             $post->setAuthor($joeywang);
             $joeywang->addPost($post);
         } else {
             $post->setAuthor($angli);
             $angli->addPost($post);
         }
         $post->setTag($this->getTags()[rand(0, 2)]);
         $post->setPublishtime(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->persist($joeywang);
     $manager->persist($angli);
     $manager->flush();
 }
예제 #2
0
 /**
  * Creates a form to delete a Post entity.
  *
  * @param Post $post The Post entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Post $post)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('post_delete', array('id' => $post->getId())))->setMethod('DELETE')->getForm();
 }