目标是有两条路线。
domain.de/wordWithMaxThreLetters
domain.de/stackoverflow
路由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 :(得分: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'
)
)
)
)
),