Symfony2 basic URL routing issue
I'm aware that my question is very...plain and simple, but I'll ask it anyway: hope that someone can give me a hint.
I'm rewriting a PHP web-application using Symfony2. My need is to perform CRUD operations on database objects (which have a primary key and other two fields, called field1
and field2
)
In my old web-app I used to recall this URL:
http://myhost/updateProduct.php?id=foo&field1=value1&field2=value2
to invoke the updateProduct.php
script to update the object having id=foo, setting value1 for field1 and value2 for field2.
Now I'm willing to use a Symfony2 controller to do that job...I wonder which routing should I set up for that. My controller is ProductController
and it embeds a up开发者_StackOverflow社区dateAction($id,$field1,$field2)
method.
I tried with something like (yml syntax):
myBundle_update:
pattern: /product/update/{id}/field1={value1}&field2={value2}
defaults: { _controller: TestMyBundle:Product:update }
but it's not working.
So my question is: I'm mistaking the routing syntax (and if so, which is the correct one)? Or is there something I am missing about how to properly split request parameters to controllers?
Thanks in advance
You probably want your route to look something like this:
pattern: /product/update/{id}/{value1}/{value2}
This way just just invoke /product/update/1/fieldValue1/fieldValue2 to update the product.
I'm not sure, but probably the routing has some problems with your route defining an & in its route.
Update: Ah, the problem lies most probably in the fact that you don't have a / between your two values. Symfony2 uses the regex [^/]+ as standard regex for a parameter.
http://symfony.com/doc/current/cookbook/routing/slash_in_parameter.html
精彩评论