2013-03-14 76 views
3

是否有这样做Zend框架2以下一个更好的解决方案:Zend框架2:多个路由到一个动作

我需要这两个网址转到一个动作 - 帮助/节/ 5和帮助/节。 ?PHP的ID = 5

我觉得这种方式太复杂了:

 'helpSection' => array(
      'type' => 'Zend\Mvc\Router\Http\Segment', 
      'options' => array(
       'route' => '/help/section/:id', 
       'defaults' => array(
        'controller' => 'Application\Controller\Help', 
        'action'  => 'section', 
       ), 
      ), 
     ), 
     'helpSection2' => array(
      'type' => 'Zend\Mvc\Router\Http\Segment', 
      'options' => array(
       'route' => '/help/section.php', 
       'defaults' => array(
        'controller' => 'Application\Controller\Help', 
        'action'  => 'section', 
       ), 
      ), 
      'child_routes' => array(
       'query' => array(
        'type' => 'Zend\Mvc\Router\Http\Query', 
        'options' => array(
         'defaults' => array(
          'id' => ':id' 
         ) 
        ) 
       ), 
      ), 
     ), 
+0

你可以送花儿给人使用重写作为替代方法,并将这些内容保留在代码库之外。 很简单,重写带有扩展名(.php)的url到不带扩展名的url。 – Andrew 2013-03-14 13:59:09

回答

0

没有测试,但是这可能实际工作......这应该符合以下几点:

  • /帮助/节
  • /帮助/节?的queryString
  • /help/section.php
  • /help/section.php?queryString
  • /帮助/节/ 1
  • /帮助/节/ 1的queryString

这将是配置:

'type' => 'segment', 
'options' => array(
    'route' => '/help/section[(.php|/:id)]', 
    'defaults' => array(
     'controller' => '...', 
     'action' => '...' 
    ), 
    'constraints' => array(
     'id' => '[0-9]+' 
    ) 
), 
'may_terminate' => true, 
'child_routes' => array(
    'query' => array(
     'type' => 'query' 
    ) 
) 
+0

不适用于这两个查询=(错误404 – 2013-03-14 14:01:32

+0

嗯,太糟糕了,我会明天检查并最终编辑,如果我得到它的工作,是值得的拍摄:P – Sam 2013-03-14 15:16:23