I am porting an outdated application to Symfony2, and I am struggling because routing does not include query string parameters. Some quick examples. Suppose you have a book search page in which you can filter the results by criteria:
http://www.bookstore.com/books?author=Stephen+King&maxPrice=20
The good thing about query string parameters in this case is that you can have any number of filters, use the ones you want for any given query, and not interpret URLs with filters that you don't use.
Let's say we rewrote the route for the above request using the Symfony2 routing component. It might look like this:
http://www.mybookstore.com/book/any_title/stephen%20king/any_release_date/max_price_20/any_min_price/any_format/any_category
Even without taking into account how arbitrarily long the unclean URL is, I still donโt find it intuitive, because each โsegmentโ of this route is not a pair of key values, but instead just a value (for example, author=Stephen+King > /stephen%20king/ ).
You can, of course, access the request lines in the controller by passing the Request object to the action method (for example, indexAction(Request $request) { ), but then checking them and passing them to other parts of the application becomes difficult (i.e. where I find myself now). What if you use the Knp Menu Bundle package to create a sidebar and want the parts to be marked as .current based on the query string parameters? There is no functionality for this, just functionality for integrating with Symfony2 routes.
And how to check the correctness of the query string parameters? I am currently considering them as a form in order to submit them to a database to generate a query. Maybe this is how the Symfony2 team intended to handle them? If so, I just really would like to know why. Looks like I'm struggling with the app.
source share