Created
April 16, 2015 10:29
-
-
Save AlmogBaku/52c98eb12dfe2e6dcd4b to your computer and use it in GitHub Desktop.
Symfony2 REST post ctrl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create new service | |
* @Post("/services/") | |
* | |
* @View("::api.html.twig") | |
* @Security("has_role('ROLE_ADMIN')") | |
* | |
* @ApiDoc( | |
* authenticationRoles={"Admin"}, | |
* input="Rimoto\PolicyBundle\Form\SCEServiceType", | |
* output="Rimoto\PolicyBundle\Entity\SCEService", | |
* statusCodes={ | |
* 200="Created new service", | |
* 400="Inserted object is not valid and have errors" | |
* } | |
* ) | |
* | |
* @param Request $request | |
* @return SCEService | |
*/ | |
public function newServiceAction(Request $request) | |
{ | |
$srv = new SCEService(); | |
$form = $this->createForm(new SCEServiceType(), $srv); | |
$form->handleRequest($request); | |
if ($form->isValid()) { | |
$em = $this->getDoctrine()->getManager(); | |
$em->persist($srv); | |
$em->flush(); | |
return $srv; | |
} | |
throw new InvalidFormException($form); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment