Zend框架2 -获取url段在随机位置作为参数


Zend Framework 2 - get url segment at random position as param

如果我的路由设置如下:

'foo' => array (
        'type' => 'segment',
        'options' => array (
                'route' => '/:foo',                                     
                'defaults' => array (
                        'controller' => 'Application'Controller'Foo',
                        'action' => 'foo' 
                ) 
        ),
        'may_terminate' => true,
        'child_routes' => array (
                'bar' => array (
                        'type' => 'segment',
                        'options' => array (
                                'route' => '/:bar[/:someMoreData]',
                                'defaults' => array(
                                        'controller' => 'Application'Controller'Foo',
                                        'action' => 'bar'
                                )
                        ),
                        'may_terminate' => true
                )
        )
)

我有这样的url:http://127.0.0.1/foo/bar/someParam (123)/someOtherParam (456789)/myParam(1、2、3)

,其中三个(或可能更多)参数的顺序是完全随机的,它们的值也可以是完全随机的。

我需要如何调整我的路由访问每个参数和它的值在我的控制器使用$this->params('myParam')或类似的?

基本上就像我可以使用查询字符串一样:http://127.0.0.1/foo/bar?myParam=1, 2、3,otherParam…

还是我误解了什么?

注意:我不能使用查询字符串

为什么不能在用例中使用查询参数?在我看来会干净得多。

无论如何,您可以使用不带任何参数的fromRoute()方法来检索所有参数。

public function myAction()
{
    $params = $this->params()->fromRoute();
}