/** * Transforms an object (anuncio) to a string (number). * * @param Anuncio|null $anuncio * @return string */ public function transform($anuncio) { if (null === $anuncio) { return ""; } return $anuncio->getId(); }
/** * Creates a new Anuncio entity. * * @Route("/create", name="anuncio_create") * @Method("POST") * @Template("SiteBundle:Anuncio:new.html.twig") */ public function createAction(Request $request) { $entity = new Anuncio(); for ($index = 0; $index < 4; $index++) { $entity->getImagenes()->add(new \SMiami\SiteBundle\Entity\Imagen()); } $form = $this->createForm(new AnuncioType(), $entity); $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $usuario = $this->get("security.context")->getToken()->getUser(); $entity->setUsuario($usuario); foreach ($entity->getImagenes() as $img) { $img->setAnuncio($entity); } $em->persist($entity); $em->flush(); return $this->redirect($this->generateUrl('pago_anuncio', array('id' => $entity->getId()))); } return array('entity' => $entity, 'form' => $form->createView()); }