Skip to content

Instantly share code, notes, and snippets.

@AlmogBaku
Created April 16, 2015 10:29
Show Gist options
  • Save AlmogBaku/52c98eb12dfe2e6dcd4b to your computer and use it in GitHub Desktop.
Save AlmogBaku/52c98eb12dfe2e6dcd4b to your computer and use it in GitHub Desktop.
Symfony2 REST post ctrl
/**
* 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