/** * Creates a new {{ entity }} entity. * {% if 'annotation' == format %} * @Route("/", name="{{ route_name_prefix }}_create") * @Method("POST") * @Template("{{ bundle }}:{{ entity }}:new.html.twig") {% endif %} */ public function createAction(Request $request) { $entity = new {{ entity_class }}(); $form = $this->createForm(new {{ entity_class }}Type(), $entity); $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); {% if 'show' in actions -%} return $this->redirect($this->generateUrl('{{ route_name_prefix }}_show', array('id' => $entity->getId()))); {%- else -%} return $this->redirect($this->generateUrl('{{ route_name_prefix }}')); {%- endif %} } {% if 'annotation' == format %} return array( 'entity' => $entity, 'form' => $form->createView(), ); {% else %} return $this->render('{{ bundle }}:{{ entity|replace({'\\': '/'}) }}:new.html.twig', array( 'entity' => $entity, 'form' => $form->createView(), )); {% endif %} }