ZF2: using url helper and reuse query parameters

前端 未结 2 599
北荒
北荒 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

    0 讨论(0)
  • 2021-01-23 23:50

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

    0 讨论(0)
提交回复
热议问题