Exemplo n.º 1
0
 /**
  * @ParamConverter("post", class="Acme\BlogBundle\Entity\Post", options={"id" = "post_id"})
  * @ParamConverter("comment", class="Acme\BlogBundle\Entity\Comment", options={"id" = "comment_id"})
  * @param Post $post
  * @param Comment $comment
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function removeAction(Post $post, Comment $comment)
 {
     if (!$this->userHasAccess($comment)) {
         throw new AccessDeniedException("Comment cannot be remove");
     }
     $em = $this->getDoctrine()->getEntityManager();
     $em->remove($comment);
     $em->flush();
     return $this->redirect($this->generateUrl('show_post', array('id' => $post->getId())));
 }
 /**
  *
  * @return Response 
  */
 public function createAction()
 {
     $post = new Post();
     $post->setTitle('Demo Blog');
     $post->setBody('Hello Symfony 2');
     $em = $this->getDoctrine()->getManager();
     $em->persist($post);
     $em->flush();
     return new Response('Created product id ' . $post->getId());
 }
Exemplo n.º 3
0
 public function load(ObjectManager $manager)
 {
     $post = new Post();
     $post->setTitle('title');
     $post->setBody('body');
     $arrayTags = array();
     $post->getTags($arrayTags);
     $manager->persist($post);
     $manager->flush();
     self::$posts[] = $post;
 }
Exemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     // Create posts
     foreach ($this->postsData as $postData) {
         $post = new Post();
         $category = $manager->getRepository('AcmeBlogBundle:Category')->findOneBySlug($postData['category']);
         $author = $manager->getRepository('AcmeUserBundle:User')->findOneByUsername($postData['user']);
         $post->setCategory($category)->setUser($author)->setName($postData['name'])->setSlug($postData['slug'])->setContent($postData['content'])->setCreated(new \DateTime($postData['created']));
         $manager->persist($post);
     }
     $manager->flush();
 }
Exemplo n.º 5
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $faker = \Faker\Factory::create('pl_PL');
     for ($i = 0; $i < self::MAX_SIZE; $i++) {
         $post = new Post();
         $post->setName($faker->sentence($nbWords = 6));
         $post->setContent($faker->paragraph($nbSentences = 50));
         $this->addReference(sprintf('comment-post-%s', $i), $post);
         $this->addReference(sprintf('tag-post-%s', $i), $post);
         $manager->persist($post);
     }
     $manager->flush();
 }