In my application, i have:
- a table storing customers’ orders, and
- a table storing order entries
so basically a one-to-many relationship between the orders table and the orders entries table (should be quite a common structure).
i have a page that display all of a customer’s orders (but not the entries). This part is simple, in my OrdersController, i have a viewAllOrdersAction which queries the DB, and send the results to the view for rendering.
Now, the next thing i want to do is, when the user clicks on a specific order, i want to go to a page which shows all the entries for that order.
i suppose i will need to add a viewOrderAction to the OrdersController which again queries the DB and send results to another view.
The question i have is regarding sending the orderId from the viewAllOrders page to the viewOrderAction and retrieving it there.
What is the right way to do this?
- Should i do a very simple form with a hidden orderId field and a link which does a submit? it does seem overkill…
- Or should i just compose a link URL with “?orderId=12345”? i would suppose this would be the better way, but how do i construct a URL with a GET param using the Zend_View’s URL helper (i.e. the $this->url(…) in a view)?
Thanks!
Option 2 is the best bet and it would look something like:
Now if you didnt have a named route with module, contorller, action speced then you could:
Assuming you have the default route enabled. Note this just ouputs the url not a full a
tagso use in it as the href attrib or usesprintfto compose the tag… I think there is a generic html tag helper so you could use that as well.Now if you dont want to expose your order ids in the url you could come up with some sort of other params to select the order itself (although this would require a join query in your view order controller) like customer username && order date or what have you simialr to how you might see a blog permalink as a date && a title “slug”.