Last active
December 17, 2015 12:09
-
-
Save benglass/5607976 to your computer and use it in GitHub Desktop.
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
<?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