我想创建的应用程序接口,有相同的网址说http://stackoverflow.com/profile,但有不同的请求方法,如POST,PUT,GET等。我想做不同的行动基于方法类型。一种方式是编写公共操作,用于比较方法和重定向使用
$this->forward('anotherModule','anotherAction');有没有其他方法可以检查它的方法并重定向到不同的操作,而不使用一个通用的操作?
发布于 2012-09-05 18:12:38
在routing.yml中,您可以根据请求方法为相同的模式定义不同的控制器
read:
pattern: /yourUrl
defaults: { _controller: your.controller:readAction }
requirements:
_method: GET
write:
pattern: /yourUrl
defaults: { _controller: your.controller:writeAction }
requirements:
_method: POST或者,如果您使用注释:
/**
* @Route("/yourRoute", requirements={"_method" = "GET"})
*/
public function showAction($id)
{
...
}
/**
* @Route("/yourRoute", requirements={"_method" = "POST"})
*/
public function writeAction($id)
{
...
}https://stackoverflow.com/questions/12279022
复制相似问题