Skip to content

Instantly share code, notes, and snippets.

@benglass
Last active December 17, 2015 12:09
Show Gist options
  • Save benglass/5607976 to your computer and use it in GitHub Desktop.
Save benglass/5607976 to your computer and use it in GitHub Desktop.
<?php
namespace VDW\FormCenterBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller,
Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use VDW\FormCenterBundle\Entity\Submission,
VDW\FormCenterBundle\Form\SubmissionType;
use FOS\RestBundle\View\View,
FOS\RestBundle\Controller\FOSRestController,
FOS\RestBundle\Controller\Annotations as Rest;
/**
* @Route("/api/{version}")
*/
class DefaultController extends FOSRestController
{
/**
* @Route("/submission/new")
* @Method({"POST"})
* @Rest\View
*/
public function newSubmissionAction(Request $request)
{
$submission = new Submission();
$form = $this->createForm(new SubmissionType(), $submission);
$form->bind($request);
if ($form->isValid()) {
$view = $this->view(array('result' => 'ok'), 200);
// Save it
$submissionManager = $this->container->get('vdw_form_center.submission.manager');
$submissionManager->saveSubmission($submission);
} else {
$view = View::create($form, 400);
}
return $this->handleView($view);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment