Php 如何在ZF2中编写符合GET参数的路由?

Php 如何在ZF2中编写符合GET参数的路由?,php,parameters,routes,zend-framework2,Php,Parameters,Routes,Zend Framework2,如何在zf2中编写允许zf1中的/:controller/:action/*等路由的路由 这样它就可以满足像controller/action/id/1/page/2和controller/action?id=1&page=2 为满足参数(如controller/action?id=1&page=2world)的路由对于ajax请求非常有用 因此,我当前的代码在我的module.config.php中看起来像这样 return array( 'controllers' => array(

如何在zf2中编写允许zf1中的
/:controller/:action/*
等路由的路由

这样它就可以满足像
controller/action/id/1/page/2
controller/action?id=1&page=2

为满足参数(如
controller/action?id=1&page=2
world)的路由对于ajax请求非常有用

因此,我当前的代码在我的module.config.php中看起来像这样

return array(
'controllers' => array(
    'invokables' => array(
        'Support\Controller\Support' => 'Support\Controller\SupportController',
    ),
),

'router' => array(
    'routes' => array(
        'support' => array(
            'type'    => 'segment',
            'options' => array(
                'route'    => '/support[/:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'     => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Support\Controller\Support',
                    'action'     => 'index',
                ),
            ),
        ),
    ),
),
'view_manager' => array(
    'template_path_stack' => array(
        'support' => __DIR__ . '/../view',
    ),
),
查看文档和中应用程序模块文件的快速根目录,告诉我您需要设置一个路由器,该路由器将匹配您要创建的url


除了Zend Framework文档之外,还有这个幻灯片,您可能会发现它很有用。它有您想要实现的代码示例。

请查看以下问题和答案:


我将尝试设置一个路由,然后添加一个使用
Zend\Mvc\Router\Http\Query

的子路由。非常感谢您的回复。我的应用程序基于框架应用程序,我已经阅读了您提供的幻灯片放映链接。它确实表示,对于段路由,它确实支持可选段(文字部分和参数部分)。我只是不太清楚怎么做。也许我错过了一些基本的东西。