2012-08-13 44 views
7

我的Zend Framework 2應用程序有一個路由定義,它試圖模仿默認的Zend Framework 1路由。它看起來像:Zend Framework 2 Part Route Assembly

 'router' => array(
      'routes' => array(
       'default' => array(
        'type' => 'segment', 
        'options' => array(
         'route' => '/[:controller[/:action]]', 
         'defaults' => array(
          '__NAMESPACE__' => 'Application\Controller', 
          'controller' => 'Index', 
          'action'  => 'index', 
         ), 
        ), 
        'may_terminate' => true, 
        'child_routes' => array(
         'wildcard' => array(
          'type' => 'wildcard', 
         ), 
        ), 
       ), 
      ), 
     ), 

它匹配的路線就好了,但我不能組裝與使用Url視圖助手任意參數路線。

例如,

$this->url('default', array('controller' => 'test', 'action' => 'test', 'id' => 5)); 

導致/test/test代替/test/test/id/5

有誰知道如何組裝這樣的部分路線?還是有更好的方式獲得ZF1風格的路線?

回答

10

事實證明,您需要在Url視圖助手中指定整個路由名稱(包括子路由)。

使用我的問題定義的路由器,適當的視圖助手通話將如下所示:

$this->url('default/wildcard', array('controller' => 'test', 'action' => 'test', 'id' => 5)); 

這將導致/test/test/id/5的URL。