2017-10-20 162 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,这取决于你想要的输出)。