すべての注釈に関する情報を共有したい。
@Get、@Post、@Put、@Delete、@Head、@Patchは、@ Route + @Method のショートカットです。両方を使用する代わりに、いずれかを指定できます。例:
/**
* @Get("/hello/{id}")
*
*/
public function helloAction($id)
{
return array();
}
@Viewに関する情報はドキュメントにあります: https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/3-listener-support.md
@View //Guess template name
@View("AcmeHelloBundle::layout.html.twig") //Load Resources/views/layout.html.twig
@View("AcmeHelloBundle::layout.html.twig", templateVar="test") // if returned data doesn't
// have a key (e.g. return array("string", 5) instead of default variable 'data',
// it's placed inside 'test' variable inside template.
@View(statusCode=204) // set HTTP header's status code
名前のプレフィックスは、routing.yml ファイルまたは注釈として追加できます。また、文書化されています - https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/6-automatic-route-generation_multiple-restful-controllers.md :
場合によっては、ルートの自動命名によってルート名の競合が発生することがあるため、RestBundle ルート コレクションは name_prefix (xml/yml の名前プレフィックスおよび注釈の @NamePrefix) パラメーターを提供します。
#src/Acme/HelloBundle/Resources/config/users_routes.yml comments:
type: rest
resource: "@AcmeHelloBundle\Controller\CommentsController"
name_prefix: api_
この構成では、ルート名は次のようになります: api_vote_user_comment
@Prefixは、親リソースがあり、子リソースの前にプレフィックスを追加する必要がある場合に特に便利です。例:
親:
class UsersController extends Controller
{
public function getUserAction($slug)
{} // "get_user" [GET] /users/{slug}
}
子:
class CommentsController extends Controller
{
public function getCommentAction($slug, $id)
{} // "get_user_comment" [GET]
}
アクション getCommentAction は/users/{slug}/comments/{id}パスに対応するようになりました。
@Prefix("some_prefix") を使用すると、生成されたパスは /users/{slug}/ some_prefix /comments/{id}になります
また、@NoRouteメソッドレベルのアノテーションを使用することで、ルートは生成されません。