I'm trying to figure 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've done, I realized that update and delete doesn't work (always calls account_read)... After googling my problem, I found out that PUT and DELETE methods aren't supported in all browsers... and may be dropped in the future.
I then read that Ruby on rails support these two methods on all browsers by doing some magic.
So I wonder, can Symfony2 handle PUT and DELETE like ruby does? AND Should I use restful url at all?
Yes, symfony2 definitively is RESTful compliant.
I don't know for rails, but Symfony2 handles HTTP methods detection using different ways:
X-HTTP-METHOD-OVERRIDE
header (fallback to _method
request parameter)Why it makes this chek on POST
is because browsers can't send nothing else but GET or POST requests.
What is different from rails and/or symfony1 is that there is no helper to generate links or forms with corresponding methods. It's up to you to generate a valid request to your application.
PS: Concerning your routing, you should write your requirements on _method in UPPERCASE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With