简体   繁体   English

Zf2子路线匹配无效

[英]Zf2 Child Route Matching do not work

The goal is to have two routes. 目标是有两条路线。

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

  3. domain.de/stackoverflow domain.de/stackoverflow

  4. domain.de/ch domain.de/ch

Route 1 default action is business Route 2 default action is countries 路线1的默认操作是企业路线2的默认操作是国家

The Problem: 问题:

The Route 2 is always executed, and i dont know why. 路线2总是执行的,我不知道为什么。 What is the mistake in my Route Config? 我的路由配置中有什么错误?

'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'
                )
            )
        )
    )
)

replace some constraints 取代一些约束

  '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'
                    )
                )
            )
        )
    ), 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM