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

putTodosAction() public method

Update existing todo from the submitted data or create a new todo at a specific location.
public putTodosAction ( Request $request, integer $id ) : Response
$request Symfony\Component\HttpFoundation\Request the request object
$id integer the todo id
return Symfony\Component\HttpFoundation\Response
    public function putTodosAction(Request $request, $id)
    {
        $todo = $this->getDoctrine()->getRepository('AcmeDemoBundle:Todo')->find($id);
        if (!$todo) {
            throw $this->createNotFoundException("Todo does not exist.");
        }
        $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);
    }