Skip to content

Instantly share code, notes, and snippets.

@Dubiy
Last active February 18, 2016 15:47
Show Gist options
  • Save Dubiy/82f2d82ccfc9e840b25d to your computer and use it in GitHub Desktop.
Save Dubiy/82f2d82ccfc9e840b25d to your computer and use it in GitHub Desktop.
edit and save example
<?php
/**
* Edit an Issue entity.
*
* @Route("/edit/{id}", requirements={"id" = "\d+"}, defaults={"id" = 0}, options={"expose": true}, name="issue_edit")
* @ParamConverter("issue", class="AppBundle\Entity\Issue", options={"id"="id"})
* @Template()
* @Method({"GET"})
*/
public function editAction(Request $request, Issue $issue)
{
$categories = $this->getDoctrine()->getRepository('AppBundle:Category')->findAll();
$colors = $this->getDoctrine()->getRepository('AppBundle:Color')->findAll();
return [
'initData' => [
'colors' => $colors,
'categories' => $categories,
'issue' => $issue
],
'issue' => $issue
];
}
/**
* Save an issue
*
* @Route("/save/{id}", requirements={"id" = "\d+"}, options={"expose": true}, name="issue_save")
* @ParamConverter("issue", class="AppBundle\Entity\Issue", options={"id"="id"})
* @Template()
* @Method({"POST"})
*/
public function saveAction(Request $request, Issue $issue)
{
$editForm = $this->createForm(IssueType::class, $issue);
$this->handleJsonForm($editForm, $request);
$this->getDoctrine()->getManager()->flush();
return new JsonResponse([
'issue' => $issue
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment