2014-01-23 67 views
0

目标是有两条路线。Zf2儿童路线匹配不起作用

  1. domain.de/wordWithMinFourLetters
  2. domain.de/wordWithMaxThreLetters

  3. domain.de/stackoverflow

  4. domain.de/ch

路线1默认动作是业务 路由2的默认操作是国家

问题:

路由2总是执行,我不知道为什么。 我的路由配置有什么错误?

'router' => array(
    'routes' => array(
     'application' => array(
      'type' => 'literal', 
      'options' => array(
       'route' => '/', 
       'defaults' => array(
        'controller' => 'index', 
        'action' => 'index' 
       ) 
      ), 
      'may_terminate' => true, 
      'child_routes' => array(
       'business' => array(
        'type' => 'segment', 
        'options' => array(
         'route' => ':business', 
         'constraints' => array(
          'business' => '[a-z]{4,10}' 
         ), 
         'defaults' => array(
          'action' => 'business' 
         ) 
        ) 
       ), 
       'countries' => array(
        'type' => 'segment', 
        'options' => array(
         'route' => ':countries', 
         'constraints' => array(
          'countries' => '[a-z]{2,3}' 
         ), 
         'defaults' => array(
          'action' => 'countries' 
         ) 
        ) 
       ) 
      ) 
     ), 
     'clear' => array(
      'type' => 'literal', 
      'options' => array(
       'route' => '/clear', 
       'defaults' => array(
        'controller' => 'index', 
        'action' => 'clear' 
       ) 
      ) 
     ), 
     'sitemap' => array(
      'type' => 'literal', 
      'options' => array(
       'route' => '/sitemap', 
       'defaults' => array(
        'controller' => 'index', 
        'action' => 'sitemap' 
       ) 
      ) 
     ) 
    ) 
) 
+0

你有一个约束的'slug',我想这应该是'business' /'countries'。 – sroes

回答

1

更换一些约束

'application' => array(
     'type' => 'Zend\Mvc\Router\Http\Literal', 
     'options' => array(
      'route' => '/', 
      'defaults' => array(
       'controller' => 'index', 
       'action' => 'index' 
      ) 
     ), 
     'may_terminate' => true, 
     'child_routes' => array(
      'business' => array(
       'type' => 'Zend\Mvc\Router\Http\Segment', 
       'options' => array(
        'route' => '/:business', // <--- update 
        'constraints' => array(
         'business' => '[a-z]{4,10}' // <----- 
        ), 
        'defaults' => array(
         'controller' => 'index', // <--- update 
         'action' => 'business' 
        ) 
       ) 
      ), 
      'countries' => array(
       'type' => 'Zend\Mvc\Router\Http\Segment', 
       'options' => array(
        'route' => '/:countries', // <--- update 
        'constraints' => array(
         'countries' => '[a-z]{2,3}' // <----- 
        ), 
        'defaults' => array(
         'controller' => 'index', // <--- update 
         'action' => 'countries' 
        ) 
       ) 
      ) 
     ) 
    ), 
+0

thanx为你助攻。如果我改变它,比我收到一个错误路由器不匹配。已更新我的路线配置,也许我有一个错误? 如果我改变了 “塞” 比我收到一个错误,如果我想的路线匹配 $ SM-> GET( '应用') - > getMvcEvent() - > getRouteMatch() - > getMatchedRouteName(); – user2521436

+0

我更新了我的答案 –

+0

托马斯你的我的英雄:D。完美的作品。 – user2521436