开发者

Correct Way to do a Simple GET with Params Link in Zend Framework?

In my application, i ha开发者_JAVA技巧ve:

  • 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?

  1. Should i do a very simple form with a hidden orderId field and a link which does a submit? it does seem overkill...
  2. 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:

<?php echo $this->url(array('order_id' => $this->order->getId()), $viewOrderRouteName); ?>

Now if you didnt have a named route with module, contorller, action speced then you could:

<?php echo $this->url(array(
    'order_id' => $this->order->getId()
    'module' => 'customer',
    'controller' => 'order',
    'action' => 'viewOrder'
), 'default' ); ?>

Assuming you have the default route enabled. Note this just ouputs the url not a full a tag so use in it as the href attrib or use sprintf to 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".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜