/** * @Route("/{slug}", name="blog_post") * @Template() */ function postAction(Request $Request, $slug) { $PostRepo = $this->getDoctrine()->getRepository('AirBlogBundle:Post'); $Post = $PostRepo->getPublishedPost($slug); if (null === $Post) { throw $this->createNotFoundException('Post nie znaleziony'); } //jeśli jest zalogowany if (null !== $this->getUser()) { $Comment = new Comment(); $Comment->setAuthor($this->getUser())->setPost($Post); $commentForm = $this->createForm(new CommentType(), $Comment); if ($Request->isMethod('POST')) { $commentForm->handleRequest($Request); if ($commentForm->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($Comment); $em->flush(); $this->get('session')->getFlashBag()->add('success', 'Komantarz dodany!'); $redirectUrl = $this->generateUrl('blog_post', array('slug' => $Post->getSlug())); return $this->redirect($redirectUrl); } } } //informuje o ataku cross script costam if ($this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) { //Stare $csrfProvider = $this->get('form.csrf_provider'); //Nowe, nie działa // $csrfProvider = $this->get('security.csrf.token_manager'); } return array('post' => $Post, 'commentForm' => isset($commentForm) ? $commentForm->createView() : null, 'csrfProvider' => isset($csrfProvider) ? $csrfProvider : null, 'tokenName' => 'delCom%d'); }
public function load(ObjectManager $manager) { $commentsList = array(array('post' => 0, 'author' => 'kowal', 'create_date' => '2012-11-10 12:41:12', 'comment' => 'Lorem ipsum dolor sit amet neque lorem, pellentesque consectetuer, tellus in faucibus lectus vestibulum vel, urna.'), array('post' => 0, 'author' => 'adas_no', 'create_date' => '2013-01-10 12:41:12', 'comment' => 'Suspendisse sed condimentum enim arcu elit, non luctus et enim.'), array('post' => 1, 'author' => 'macq', 'create_date' => '2013-05-11 15:41:12', 'comment' => 'Phasellus fermentum mi, nec urna ullamcorper ut, eleifend nibh, pretium convallis. Fusce facilisis hendrerit.'), array('post' => 2, 'author' => 'antkow', 'create_date' => '2012-11-10 12:41:12', 'comment' => 'Donec libero malesuada fames ac lacus. Nullam accumsan. In euismod rutrum, enim nec diam at ipsum.'), array('post' => 2, 'author' => 'adas_no', 'create_date' => '2013-01-10 12:41:12', 'comment' => 'Donec sit amet, consectetuer adipiscing elit. Quisque iaculis.'), array('post' => 1, 'author' => 'kowal', 'create_date' => '2013-05-11 15:41:12', 'comment' => 'Aliquam hendrerit tellus non nunc. Nam ut eros tincidunt turpis egestas. Suspendisse bibendum risus.')); foreach ($commentsList as $details) { $Comment = new Comment(); $Comment->setAuthor($this->getReference('user-' . $details['author']))->setCreateDate(new \DateTime($details['create_date']))->setPost($this->getReference('post-' . $details['post']))->setComment($details['comment']); $manager->persist($Comment); } $manager->flush(); }
/** * {@inheritDoc} */ public function setAuthor(\Common\UserBundle\Entity\User $author) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setAuthor', array($author)); return parent::setAuthor($author); }