Last active
February 18, 2016 15:47
-
-
Save Dubiy/82f2d82ccfc9e840b25d to your computer and use it in GitHub Desktop.
edit and save example
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 | |
/** | |
* 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