Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pimpreneil
Last active January 7, 2016 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pimpreneil/cc9c0fbcb4452008af32 to your computer and use it in GitHub Desktop.
Save pimpreneil/cc9c0fbcb4452008af32 to your computer and use it in GitHub Desktop.
Sexy routing (avoiding magical annotations)
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+
<?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