Is Symfony2 handling the calm URL correctly and should I use the calm url?

I am trying to figure out what is the best way to design my urls. So here is what I have done so far:

account_index:
    pattern:  /Accounts/
    defaults: { _controller: "CoreBundle:Account:index" }
    requirements: { _method: get }

account_create:
    pattern:  /Accounts/
    defaults: { _controller: "CoreBundle:Account:create" }
    requirements: { _method: post }

account_read:
    pattern:  /Accounts/{id}
    defaults: { _controller: "CoreBundle:Account:show" }
    requirements: { _method: get }

account_update:
    pattern:  /Accounts/{id}
    defaults: { _controller: "CoreBundle:Account:update" }
    requirements: { _method: put }

account_delete:
    pattern:  /Accounts/{id}
    defaults: { _controller: "CoreBundle:Account:delete" }
    requirements: { _method: delete }

After testing what I did, I realized that updating and deleting do not work (always causes account_read) ... After I tried to solve my problem, it turned out that the PUT and DELETE methods are not supported in all browsers ... and may be omitted in the future.

Then I read that Ruby on rails supports these two methods in all browsers, doing magic.

So I wonder if Symfony2 can handle PUT and DELETE like a ruby? AND ALSO Should I use a residual url at all?

+5
source
3

, symfony2 RESTful.

, Symfony2 HTTP :

  • REQUEST_METHOD php
  • , == POST, X-HTTP-METHOD-OVERRIDE ( _method )

chek POST, , GET POST.

/ symfony1, , . .

PS: , _method UPPERCASE.

+12

RESTful, RestBundle. , , , .

, Symfony2 PUT DELETE.

+3

It's not what Symfony can or cannot do, it’s how the "Restful url" handle with the current browsers available ...

Some browsers will not allow you to use some HTTP methods (e.g. put or delete), so yes, a good implementation will use GET, POST, PUT, DELETE and PATCH, but you will get problems with some users :)

As always ... browsers ...

+1
source

All Articles