当我去:http://mysite.com/web/app_dev.php/user/register
我得到了:
MethodNotAllowedHttpException: No route found for "GET /user/register": Method Not Allowed (Allow: POST)
这是我的代码:
MainUserBundle_register:
pattern: /user/register/
defaults: { _controller: MainUserBundle:UserAuthWebService:register, _format:json}
requirements:
_method: POST
我的控制器是:
public function registerAction($email="test", $username="test", $password="test123")
{
//some code
}
为什么?
答案 0 :(得分:11)
您可以将路由限制为仅匹配给定的HTTP方法。在您发布的代码中,路由仅匹配POST
个请求。您需要允许POST
和GET
,或一起删除所有要求。
MainUserBundle_register:
pattern: /user/register/
defaults: { _controller: MainUserBundle:UserAuthWebService:register, _format:json}
requirements:
_method: POST|GET
http://symfony.com/doc/current/book/routing.html#adding-http-method-requirements