php - Symfony2: FOSRest: Allow route for both "/api/items" and "api/items/{id}" -
so, i'm trying create simple rest api symfony2 , fosrestbundle.
it's going well, i've hit wall google apparantly hasnt been able answer :)
i understand this:
public function getusersaction(){ return 'a list of users'; } will create route such:
api_get_users /api/users.{_format} and know add function parameter:
public function getusersaction($id){ return 'a specific users (with $id) details'; } will create route such:
api_get_users /api/users/{userid}.{_format} however if want make it, both routes available (like proper rest api design)?
i tried doing
public function getusersaction($userid = null){ but didnt work (not huge surprise)..
i'm pretty sure i'm missing simple piece of puzzle, have no idea what.
creating getuseraction($id) , getusersaction() (not plural) should work, according the documentation:
class usercontroller implements classresourceinterface { // ... public function getusersaction() {} // "get_users" [get] /users public function getuseraction($slug) {} // "get_user" [get] /users/{slug} // or when omittig "user": public function cgetaction() {} // "get_users" [get] /users public function getaction($slug) {} // "get_user" [get] /users/{slug} // ... }
Comments
Post a Comment