Skip to content

Instantly share code, notes, and snippets.

@andersonfraga
Created October 26, 2011 17:19
Show Gist options
  • Save andersonfraga/1317055 to your computer and use it in GitHub Desktop.
Save andersonfraga/1317055 to your computer and use it in GitHub Desktop.
Proposal Bundle Restful for Symfony
<?php
namespace App;
use Restsym/Controller;
use Restsym/Controller/RespondTo;
use App/News/Repository as DataNews;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class News {
function respondTo() {
return array(
'html', 'json'
);
}
function get() {
$news = new DataNews;
// list news returned
return $news->getList();
}
/**
* @Route("/news/{id}", name="_get_news")
*/
function get_news($id) {
$news = new DataNews($id);
return $news->content();
}
function post($form) {
$news = new DataNews;
// return id new news
// and redirect for get (if html)
return $news->create($form);
}
function put($id, $form) {
$news = new DataNews($id);
// return true if edited with success
// and redirect for get
return $news->edit($form);
}
function delete($id) {
$news = new DataNews($id);
// return true if deleted with success
// and redirect for get
return $news->delete();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment