Bundle/TemplateBundle/Controller/TemplateController.php
public function newAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $template = new Template();
        $form = $this->container->get('form.factory')->create(TemplateType::class, $template);

        $form->handleRequest($request);
        if ($form->isValid()) {
            $em->persist($template);
            $em->flush();

            return new JsonResponse([
                'success' => true,
                'url'     => $this->generateUrl('victoire_template_show', ['id' => $template->getId()]),
            ]);
        }

        return new JsonResponse(
            [
                'success' => true,
                'html'    => $this->container->get('templating')->render(
                    'VictoireTemplateBundle:Template:new.html.twig',
                    ['form' => $form->createView()]
                ),
            ]
        );
    }
public function newAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $template = new Template();
        $form = $this->container->get('form.factory')->create(TemplateType::class, $template);

        $form->handleRequest($request);
        if ($form->isValid()) {
            $em->persist($template);
            $em->flush();

            return new JsonResponse([
                'success' => true,
                'url'     => $this->generateUrl('victoire_template_show', ['id' => $template->getId()]),
            ]);
        }

        return new JsonResponse(
            [
                'success' => true,
                'html'    => $this->container->get('templating')->render(
                    'VictoireTemplateBundle:Template:new.html.twig',
                    ['form' => $form->createView()]
                ),
            ]
        );
    }
public function newAction ( Request $ request ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ template = new Template ( ) ; $ form = $ this -> container -> get ( 'form.factory' ) -> create ( TemplateType :: class , $ template ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em -> persist ( $ template ) ; $ em -> flush ( ) ; return new JsonResponse ( [ 'success' => true , 'url' => $ this -> generateUrl ( 'victoire_template_show' , [ 'id' => $ template -> getId ( ) ] ) , ] ) ; } return new JsonResponse ( [ 'success' => true , 'html' => $ this -> container -> get ( 'templating' ) -> render ( 'VictoireTemplateBundle:Template:new.html.twig' , [ 'form' => $ form -> createView ( ) ] ) , ] ) ; }
create a new Template.

@return JsonResponse
@Route("/new", name="victoire_template_new")
@Configuration\Template()
create a new Template .