Acme\DemoBundle\Controller\TodoController::postTodosAction PHP Method

postTodosAction() public method

Creates a new todo from the submitted data.
public postTodosAction ( Request $request ) : Symfony\Component\Form\FormTypeInterface | FOS\RestBundle\View\RouteRedirectView
$request Symfony\Component\HttpFoundation\Request the request object
return Symfony\Component\Form\FormTypeInterface | FOS\RestBundle\View\RouteRedirectView
    public function postTodosAction(Request $request)
    {
        $todo = new Todo();
        $form = $this->createForm(new TodoType(), $todo);
        $form->submit($request);
        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($todo);
            $em->flush();
            $view = $this->routeRedirectView('get_todo', ['id' => $todo->getId()])->setTemplate('AcmeDemoBundle:Todo:getTodo.html.twig')->setTemplateVar('todo')->setData($todo);
        } else {
            $view = $this->view(['form' => $form], 400);
        }
        return $this->handleView($view);
    }