Skip to content

Instantly share code, notes, and snippets.

@frastel
Last active December 10, 2015 00:49
Show Gist options
  • Save frastel/4354236 to your computer and use it in GitHub Desktop.
Save frastel/4354236 to your computer and use it in GitHub Desktop.
<?php
namespace Acme\DemoBundle\Controller;
class ThinController extends Controller
{
/**
* @Route("/", name="some_index_route")
* @Template()
*/
public function indexAction($limit)
{
$list = $this->get('model.list_handler')->getList($limit);
return array('list' => $list);
}
/**
* @Route("/{id}/edit", name="some_edit_route")
* @Method({"GET"})
* @Template()
*/
public function editAction($id)
{
// the form_handler service depends an another finder_handler
// which could load the entity within the init method
$form = $this->get('model.form_handler')->createForm($id);
return array('form' => $form);
}
/**
* @Route("/{id}/edit", name="some_update_route")
* @Method({"POST"})
* @Template("AcmeDemoBundle:ThinController:edit.html.twig")
*/
public function updateAction(Request $request, $id)
{
// throws exception when model is not found
$form = $this->get('model.form_handler')->createForm($id);
$form->bind($request);
try {
$entity = $form->getData();
$this->get('model.persistence_handler')->update($entity);
} catch (HandlerValidationException $e) {
// some error handling here
}
$this->redirect($this->generateUrl('some_edit_route', array('id' => $entity->getId())));
}
/**
* @Route("/{id}", name="some_show_route", requirements={"id" = "\d+"})
* @Template()
*/
public function showAction($id)
{
$model = $this->get('model.finder')->load($id);
return array('model' => $model);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment