2013-06-06 81 views
0

您好我是zend framework 2.2.0中的新成員。我想創建一個鏈接去刪除頁面現在我只在URL中傳遞id,所以我想通過其中的另一個ID。一個鏈接在zend框架中傳遞多個參數

<a href="<?php echo $this->url('message',array('action'=>'delete', 'id' => $message->message_id));?>">Add to Trash</a> 

現在在這個環節上消息ID走過時,我也想通過一個名爲多個ID在這個環節

<a href="<?php echo $this->url('message',array('action'=>'delete', 'id' => $message->message_id,'did'=>$message->deliver_id));?>">Add to Trash</a> 

我怎樣才能得到這個「做」? 由於事先

+0

看到這麼張貼http://stackoverflow.com/questions/12785190/how-can-you-add-query-parameters-in-the-zf2-url-view-helper –

回答

0

你要「做」添加到您的郵件路線是這樣的:

'router' => array(
    'routes' => array(
     'message' => array(
      'type' => 'segment', 
      'options' => array(
       'route' => '/:action/:id[/:did]', 
       'constraints' => array(
        'action' => '[a-zA-Z][a-zA-Z0-9_-]+', 
        'id'  => '[0-9]+', 
        'did' => '[0-9]+', 
       ), 
       'defaults' => array(
        'controller' => 'Application\Controller\Index', 
       ), 
      ), 
     ), 
    ), 
), 

echo $this->url('message',array('action'=>'delete', 'id' => $message->message_id,'did'=>$message->deliver_id); 
// output: /delete/1/2 
1

您應該使用URL視圖助手的第三個參數($選項)來傳遞您的變量在查詢字符串。例如:

​​
+0

我會也建議這種方法。但它取決於URL應該是什麼樣子以及開發者想要如何訪問params(通過路由()或fromPost())。 – Sam