src/PN/Bundle/ProductBundle/Controller/Administration/OccasionController.php
/**
     * Displays a form to create a new Occasion entity.
     *
     * @Route("/new", name="occasion_new", methods={"GET", "POST"})
     */
Displays a form to create a new Occasion entity.
Displays a form to create a new Occasion entity .
public function newAction(Request $request)
    {
        $this->denyAccessUnlessGranted(['ROLE_ADMIN', 'ROLE_MANAGE_PRODUCTS']);
        $occasion = new Occasion();
        $form = $this->createForm(OccasionType::class, $occasion);
        $form->handleRequest($request);
        if ($form->isValid() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $userName = $this->get('user')->getUserName();
            $occasion->setCreator($userName);
            $occasion->setModifiedBy($userName);
            $em->persist($occasion);
            $em->flush();
            $this->addFlash('success', 'Successfully saved');
            if ($request->request->get("action") == "saveAndNext") {
                return $this->redirectToRoute('occasion_manage_product', ["id" => $occasion->getId()]);
            }
            return $this->redirectToRoute('occasion_index');
        }
        return $this->render("product/admin/occasion/new.html.twig", [
            'occasion' => $occasion,
            'form' => $form->createView(),
        ]);
    }
public function newAction ( Request $ request ) { $ this -> denyAccessUnlessGranted ( [ 'ROLE_ADMIN' , 'ROLE_MANAGE_PRODUCTS' ] ) ; $ occasion = new Occasion ( ) ; $ form = $ this -> createForm ( OccasionType :: class , $ occasion ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) && $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ userName = $ this -> get ( 'user' ) -> getUserName ( ) ; $ occasion -> setCreator ( $ userName ) ; $ occasion -> setModifiedBy ( $ userName ) ; $ em -> persist ( $ occasion ) ; $ em -> flush ( ) ; $ this -> addFlash ( 'success' , 'Successfully saved' ) ; if ( $ request -> request -> get ( " action " ) == " saveAndNext " ) { return $ this -> redirectToRoute ( 'occasion_manage_product' , [ " id " => $ occasion -> getId ( ) ] ) ; } return $ this -> redirectToRoute ( 'occasion_index' ) ; } return $ this -> render ( " product/admin/occasion/new.html.twig " , [ 'occasion' => $ occasion , 'form' => $ form -> createView ( ) , ] ) ; }
Displays a form to create a new Occasion entity.
Displays a form to create a new Occasion entity .