public function postAction(Request $request)
    {
        /**
         * @var $em ApiEntityManager
         */
        $em = $this->getDoctrine()->getManager();

        $data = json_decode($request->getContent(), true);
        $entity = $em->createEntity($this->entityClassName());

        $form = $this->createForm($this->formClassName(), $entity, [
            "method" => $request->getMethod(),
        ]);

        $form->submit($data);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($entity);
            $em->flush();

            return $entity;
        }

        return FOSView::create([
            'errors' => $form->getErrors()
        ], Response::HTTP_INTERNAL_SERVER_ERROR);
    }
public function postAction(Request $request)
    {
        /**
         * @var $em ApiEntityManager
         */
        $em = $this->getDoctrine()->getManager();

        $data = json_decode($request->getContent(), true);
        $entity = $em->createEntity($this->entityClassName());

        $form = $this->createForm($this->formClassName(), $entity, [
            "method" => $request->getMethod(),
        ]);

        $form->submit($data);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($entity);
            $em->flush();

            return $entity;
        }

        return FOSView::create([
            'errors' => $form->getErrors()
        ], Response::HTTP_INTERNAL_SERVER_ERROR);
    }
public function postAction ( Request $ request ) { /**
         * @var $em ApiEntityManager
         */ $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ data = json_decode ( $ request -> getContent ( ) , true ) ; $ entity = $ em -> createEntity ( $ this -> entityClassName ( ) ) ; $ form = $ this -> createForm ( $ this -> formClassName ( ) , $ entity , [ "method" => $ request -> getMethod ( ) , ] ) ; $ form -> submit ( $ data ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ entity ) ; $ em -> flush ( ) ; return $ entity ; } return FOSView :: create ( [ 'errors' => $ form -> getErrors ( ) ] , Response :: HTTP_INTERNAL_SERVER_ERROR ) ; }
Create a Product entity.

@ApiDoc

@View(statusCode=201, serializerEnableMaxDepthChecks=true)

@param Request $request

@return object
Create a Product entity .