Skip to content

Instantly share code, notes, and snippets.

@hubgit
Created August 17, 2012 15:43
Show Gist options
  • Save hubgit/3380014 to your computer and use it in GitHub Desktop.
Save hubgit/3380014 to your computer and use it in GitHub Desktop.
FosRestBundle Controller inheritance
<?php
/**
* RestController extends FosRestController, and provides generic CRUD actions for collections and resources.
*/
class ArticleController extends RestController
{
/**
* Display the collection (GET)
*
* @param ParamFetcher $paramFetcher
*
* @View()
*
* @QueryParam(name="limit", requirements="\d+", default="10", description="items per page")
* @QueryParam(name="offset", requirements="\d+", default="0", description="offset")
*
* @return array
*/
public function getArticlesAction(ParamFetcher $paramFetcher)
{
return parent::retrieveCollection($paramFetcher);
}
/**
* Create a new item (POST)
*
* @View()
*
* @return \FOS\RestBundle\View\RedirectView
*/
public function postArticlesAction()
{
return parent::createItem();
}
/**
* Display the item (GET)
*
* @param string $id entity id
*
* @View()
*
* @return Article
*/
public function getArticleAction($id)
{
return parent::retrieveItem($id);
}
/**
* Update an existing item (PUT)
*
* @param string $id entity id
*
* @View()
*
* @return \FOS\RestBundle\View\RedirectView
*/
public function putArticleAction($id)
{
return parent::updateItem($id);
}
/**
* Delete an item (DELETE)
*
* @param string $id entity id
*
* @View()
*
* @return \FOS\RestBundle\View\RedirectView
*/
public function deleteArticleAction($id)
{
return parent::deleteItem($id);
}
/*********************
* Forms
*********************/
/**
* Form for creating a new item (GET)
*
* @View()
*
* @return \Symfony\Component\Form\Form
*/
public function newArticleAction()
{
return parent::entityForm();
}
/**
* Form for updating an existing item (GET)
*
* @param string $id entity id
*
* @View()
*
* @return \Symfony\Component\Form\Form
*/
public function editArticleAction($id)
{
return parent::entityForm($id);
}
@maximelebastard
Copy link

Hi ! It seems very interesting, but where can we find your RestController class ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment