Last active
January 7, 2016 11:26
-
-
Save pimpreneil/cc9c0fbcb4452008af32 to your computer and use it in GitHub Desktop.
Sexy routing (avoiding magical annotations)
This file contains hidden or 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
some_edit_route: | |
path: /{id}/edit | |
defaults: | |
_controller: AmceDemoBundle:Thin:edit | |
_template: AmceDemoBundle:Thin:edit.html.twig | |
methods: [GET] | |
requirements: | |
id: \d+ | |
some_update_route: | |
path: /{id}/edit | |
defaults: | |
_controller: AmceDemoBundle:Thin:update | |
_template: AmceDemoBundle:Thin:edit.html.twig | |
methods: [POST] | |
requirements: | |
id: \d+ |
This file contains hidden or 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 | |
class ThinController | |
{ | |
public function editAction(Request $request, $_template) | |
{ | |
$id = $request->attributes->get('id'); | |
$form = $this->get('model.form_handler')->createForm($id); | |
return $this->render($_template, array('form' => $form)); | |
} | |
public function updateAction(Request $request, $_template) | |
{ | |
$id = $request->attributes->get('id'); | |
$form = $this->get('model.form_handler')->createForm($id); | |
$form->handleRequest($request); | |
try { | |
$entity = $form->getData(); | |
$this->get('model.persistence_handler')->update($entity); | |
} catch (HandlerValidationException $e) { | |
// some error handling here | |
} | |
return $this->render($_template, array('form' => $form)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment