2017-10-20 167 views
1

我試圖做使用url view helper in Zend Framework 2Zend框架2正從路徑URL

,我試圖生成URL應該 my-website.com/app/##是生成一個URL(其中##等於「OWNERID」)

當我生成這個使用這樣的視圖助手會發生什麼:

$this->url('mymodule', array('action'=>'show', 'ownerID'=>'28')); 

是它只產生「my-website.com/app」,但我期望基於路由配置的「my-website.com/app/28」。

這裏是我的module.config.php文件

'router' => array(
'routes' => array(
    'mymodule' => array(
     'type' => 'segment', 
     'options' => array(
      'route' => '/app', 
      'defaults' => array(
       'controller' => 'MyModule\Controller\MyModule', 
       'action'  => 'show', 
      ), 
     ), 
     // Defines that "/app" can be matched on its own without a child route being matched 
     'may_terminate' => true, 
     'child_routes' => array(
      'archive' => array(
       'type' => 'segment', 
       'options' => array(
        'route' => '/:action[/:ownerID[/:clientID]]', 
        'defaults' => array(
        ), 
        'constraints' => array(
         'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         'ownerID'  => '[0-9]+',        
         'clientID'  => '[0-9]+', 
        ) 
       ), 
      ), 
      'single' => array(
       'type' => 'segment', 
       'options' => array(
        'route' => '/:ownerID[/:clientID]', 
        'defaults' => array(
         'action'  => 'show', 
        ), 
        'constraints' => array(
         'ownerID'  => '[0-9]+', 
         'clientID'  => '[0-9]+', 
        ) 
       ), 
      ), 
     ) 
    ), 
) 
), 

路由信息時,使用這 - $>重定向會發生同樣的行爲() - > toRoute。

所有路線都按預期方式工作,當您手動鍵入它們時,它只是導致我難住的URL的一代。

回答

0

爲了更直接地回答這個問題,它沒有達到您的期望,因爲您只是將頂級路由名稱(「mymodule」)傳遞給URL助手。 ownerID是兒童路線的一部分。

你真正想要的是:

$this->url('mymodule/archive', array('action'=>'show', 'ownerID'=>'28')); 

(或可能mymodule/single,這取決於你想要的輸出)。