function getPostsAction() { } public function getPostAction($id) { } public function postPostAction() { } public function putPostAction($id) { } public function deletePostAction($id) { } } Routing
------------- -------- -------- ------ ----------------------- Name Method Scheme Host Path ------------- -------- -------- ------ ----------------------- get_posts GET ANY ANY /posts.{_format} get_post GET ANY ANY /posts/{id}.{_format} post_post POST ANY ANY /posts.{_format} put_post PUT ANY ANY /posts/{id}.{_format} delete_post DELETE ANY ANY /posts/{id}.{_format} ------------- -------- -------- ------ ----------------------- Routing
... public function postPostCommentAction($postId) { } public function getPostCommentsAction($postId) { } public function getPostCommentAction($postId, $commentId) { } } Routing mit Subressourcen
------------------- -------- -------- ------ ------------------------------------------------ Name Method Scheme Host Path ------------------- -------- -------- ------ ------------------------------------------------ get_posts GET ANY ANY /posts.{_format} get_post GET ANY ANY /posts/{id}.{_format} post_post POST ANY ANY /posts.{_format} put_post PUT ANY ANY /posts/{id}.{_format} delete_post DELETE ANY ANY /posts/{id}.{_format} post_post_comment POST ANY ANY /posts/{postId}/comments.{_format} get_post_comments GET ANY ANY /posts/{postId}/comments.{_format} get_post_comment GET ANY ANY /posts/{postId}/comments/{commentId}.{_format} ------------------- -------- -------- ------ ------------------------------------------------ Routing mit Subressourcen
Response Listener use FOS\RestBundle\Controller\FOSRestController; class PostController extends FOSRestController { public function getPostAction($id) { // find the blog post by id $post = $this->findPost($id); if (null === $post) { $view = $this->view(null, 404); } else { $view = $this->view($post); } return $view; } }
class PostController extends FOSRestController { public function getPostAction($id) { // find the blog post by id $post = $this->findPost($id); if (null === $post) { $view = $this->view(null, 404); } else { $view = $this->view($post); } return $view; } }
class PostController { use ControllerTrait; public function getPostAction($id) { // find the blog post by id $post = $this->findPost($id); if (null === $post) { $view = $this->view(null, 404); } else { $view = $this->view($post); } return $view; } }