找不到“GET / user / register”的路由:方法不允许(允许:POST)

时间:2012-06-28 18:55:04

标签: php symfony

当我去: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

    }

为什么?

1 个答案:

答案 0 :(得分:11)

您可以将路由限制为仅匹配给定的HTTP方法。在您发布的代码中,路由仅匹配POST个请求。您需要允许POSTGET,或一起删除所有要求。

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