2014-01-23 101 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