在Zend Framework 2中是否有更好的解决方案:
我需要这两个URL去一个动作-帮助/节/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'
)
)
),
),
),
未测试,但这可能实际上工作…它应该匹配以下内容:
- <
- /帮助/部分/gh>
- /帮助/节吗?参数
- /帮助/section.php
- /帮助/section.php吗?参数 1 <
- /帮助/部分//gh>
- /帮助/部分/1 ?参数
这将是配置:
'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'
)
)