设置路由';s在使用FOSRestBundle时允许使用带注释的方法


Set route's allowed methods with annotation when using FOSRestBundle

我想知道是否有一种简单的方法可以更改在routing.yml:中使用type: rest通过FOSRestBundle生成的路由的允许方法

例如,我有:

public function regularAction()
{
}

转化为:

Name                             Method     Scheme   Host   Path
-------------------------------- ---------- -------- ------ -----------------------
pria_core_regular                GET        ANY      ANY    /regular.{_format}

我可以更改FOS'RestBundle'Controller'Annotations'Route'Method注释生成的路径:

/**
 * @Route("/test-regular")
 */
public function regularAction()
{
}

然后路线如我所料:

Name                             Method     Scheme   Host   Path
-------------------------------- ---------- -------- ------ -----------------------
pria_core_regular                GET        ANY      ANY    /test-regular.{_format}

然而,我不能用重写允许的方法来做同样的事情。例如:

@Method({"GET", "POST"})

使用@Method没有效果。FOSRestBundle是否有意禁用此功能?

为了设置请求方法,请实现如下路由:

// Get Action
public function getRegular() {}
// Post Action 
public function postRegular() {}

编辑:很抱歉,我没有100%理解这个问题,用get/post等准备你的控制器方法会设置方法,请参阅此处