/** * Crea una entrada del blog */ public function newAction() { $blog = new Blog(); $document1 = new Document(); $blog->addDocument($document1); $form = $this->createForm(new BlogType(), $blog); $request = $this->getRequest(); if ($request->getMethod() == 'POST') { $form->submit($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); //comprobar como simplificar esta linea que llama dos veces $securityContext = $this->container->get('security.context'); $username = $this->container->get('security.context')->getToken()->getUser(); if ($securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) { $blog->setAuthor($username); } else { $blog->setAuthor("Anónimo"); } $imagenes = $blog->getDocuments(); foreach ($imagenes as $imagen) { if ($imagen->getName() == null) { $imagen->setName("Imagen sin Descripción"); } if ($imagen->getPath() == null) { $imagen->setPath("Sin Ubicación"); } } $blog->setTags("etc"); $blog->setCreated(new \DateTime()); $blog->setUpdated($blog->getCreated()); //ladybug_dump_die($categoria); $em->persist($blog); $em->flush(); $this->get('session')->getFlashBag()->add('success', 'flash.create.success'); // reenvíe el formulario si actualiza la página return $this->redirect($this->generateUrl('blogger_blog_newseccion')); } } return $this->render('BloggerBlogBundle:Blog:new.html.twig', array('form' => $form->createView())); }