ZF2: using url helper and reuse query parameters

笑着哭i 提交于 2019-12-02 03:57:15

I think what you are looking for is a Query route type to capture the Query string for you as a child route:

'route' => array(
    'type'    => 'literal',
    'options' => array(
        'route'    => 'page',
        'defaults' => array(
        ),
    ),
    'may_terminate' => true,
    'child_routes'  => array(
        'query' => array(
            'type' => 'Query',
            'options' => array(
                'defaults' => array(
                    'foo' => 'bar'
                )
            )
        ),
    ),

You can then use the view helper to generate and append the query string for you. If you don't use a Query child route, then the helper will just ignore your query string.

$this->url(
    'page/query',
    array(
        'name'=>'my-test-page',
        'format' => 'rss',
        'limit' => 10,
    )
);

You can then set the third parameter to TRUE and allow the helper to use the current parameters as you are trying to do in your example.

There's examples in the docs:

http://framework.zend.com/manual/2.0/en/modules/zend.mvc.routing.html

You could use something like this, but the query parameters arent reused in my case.

$this->url(
    'page/query',
    array(),
    array(
        'query' => array(
            'name'=>'my-test-page',
            'format' => 'rss',
            'limit' => 10,
        )
    ),
    true
);

So if you want to reuse query parameters you coul merge them with your new ones and then add all of them to the query array (3 parameter).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!