php - Zend 框架 2 : multiple routes to one action

标签 php routing get zend-framework2

在 Zend Framework 2 中执行以下操作是否有更好的解决方案:

我需要这两个 URL 执行一项操作 - help/section/5 和 help/section.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'
                        )
                    )
                ),
            ),
        ),

最佳答案

未经测试,但这可能确实有效......它应该符合以下条件:

  • /帮助/部分
  • /help/section?queryString
  • /help/section.php
  • /help/section.php?queryString
  • /help/section/1
  • /help/section/1?queryString

这将是配置:

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

关于php - Zend 框架 2 : multiple routes to one action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15409095/

相关文章:

android - 通过 MediaRouter 将音频流式传输到设备

jquery - 在 header 中设置接受语言

php - 保留 .htaccess 中的 & 符号登录 URL

php - 根据搜索条件在 PHP 中嵌入 SQL 搜索 $var

php - 如何从数组中的每个对象获取对象属性?

php - 给定一个数组数组,如何从每个值中去除子字符串 "GB"?

c# - 从 MVC 4 中的 URL 获取 "Id"值

ruby-on-rails-3 - 如何从 Ruby on Rails 3 中的模型路由和渲染(调度)

node.js - 在获取中自动填充 cookie(如浏览器)

php - local.ERROR : cURL error 7: Failed to connect to 127. 0.0.1 端口 7700:连接被拒绝