public function load(ObjectManager $manager)
 {
     for ($i = 0; $i < 100; $i++) {
         $post = new Post();
         $post->setTitle(sprintf('Titre du post n°%d', $i));
         $post->setBody(sprintf('Corps du post n°%d', $i));
         $post->setPublished($i % 2);
         $manager->persist($post);
     }
     // To finish
 }
Пример #2
0
 /**
  * Displays a form to edit an existing Post entity.
  *
  * @Route("/{id}/edit")
  * @Method({"GET", "POST"})
  * @Template()
  * @I18nDoctrine
  */
 public function editAction(Request $request, Post $post)
 {
     if (is_object($post->getPublished()) && $post->getPublished()->format('dmY') == '3011-0001') {
         $post->setPublished(null);
     }
     $deleteForm = $this->createDeleteForm($post);
     $editForm = $this->createForm('BlogBundle\\Form\\PostType', $post);
     $editForm->handleRequest($request);
     if ($editForm->isSubmitted() && $editForm->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($post);
         $em->flush();
         $this->get('session')->getFlashBag()->add('success', 'post.edited');
         return $this->redirectToRoute('blog_post_show', array('id' => $post->getId()));
     }
     return array('entity' => $post, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView());
 }