Created
August 17, 2012 15:43
-
-
Save hubgit/3380014 to your computer and use it in GitHub Desktop.
FosRestBundle Controller inheritance
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 | |
/** | |
* 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi ! It seems very interesting, but where can we find your RestController class ?