No route found for "GET / user / register": method not allowed (enable: POST)

When I go to: http://mysite.com/web/app_dev.php/user/register

I get:

MethodNotAllowedHttpException: No route found for "GET /user/register": Method Not Allowed (Allow: POST) 

Here is my code:

MainUserBundle_register:
    pattern:  /user/register/
    defaults: { _controller: MainUserBundle:UserAuthWebService:register, _format:json}
    requirements:
        _method:  POST

my controller:

 public function registerAction($email="test", $username="test", $password="test123")
    {


       //some code

    }

Why?

+5
source share
1 answer

You can restrict the route to only matching this HTTP method. In the code you sent, the route will correspond only to requests POST. You will need to allow POSTand GETor delete everything together.

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

+11
source

All Articles