ZF2: using url helper and reuse query parameters

前端 未结 2 631
北荒
北荒 2021-01-23 22:45

I\'m trying to reuse query params using Url helper in a view. This is my current url:

http://localhost/events/index?__orderby=name&__order=asc
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-23 23:48

    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

提交回复
热议问题