Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Url view helper and controller plugin feature to reuse matched query args #74

Open
GeeH opened this issue Jun 28, 2016 · 2 comments
Open

Comments

@GeeH
Copy link
Contributor

GeeH commented Jun 28, 2016

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7350
User: @27cm
Created On: 2015-03-20T07:41:10Z
Updated At: 2015-11-06T20:58:33Z
Body
There is no easy way to reuse query arguments via url view helper or controller plugin. If current page has some query arguments (a view template doesn't know about them) and it's necessary to create url to this page, remove some query arguments or/and add some other arguments.

For example current page is /blog?sort=date&order=asc
It's necessary to create url /blog?sort=date&order=asc&page=2 - add argument page=2 and save other arguments, if they were.

$this->url(null, [], ['query' => ['page' => 2]], true); 
// returns '/blog?sort=date&order=asc&page=2'

$this->url(null, [], ['query' => ['page' => 2]], false); 
// returns '/blog?page=2'

Now current page is /blog?sort=date&order=asc&page=2
It's necessary to create url /blog?sort=date&order=asc - remove argument page and save other arguments, if they were.

$this->url(null, [], ['unset_query_params' => ['page']], true);
// returns '/blog?sort=date&order=asc'

To realize it I rewrote Url View Helper. But it isn't a good solution. I think it's necessary to go deeper, to Route.

So I would like to discuss this feature.


@bartoszzajac
Copy link

bartoszzajac commented Oct 27, 2016

I wrote my own url helper that wraps oryginal helper and adds functionality to reuse query parameters. I need to inject request to get current query.

public function __invoke($route = null, $params = [], $options = [])
{
    $requestQuery     = $this->request->getQuery()->toArray();
    $optionsQuery     = isset($options['query']) ? $options['query'] : [];
    $options['query'] = \array_merge($requestQuery, $optionsQuery);

    return $this->view->url($route, $params, $options);
}

Couldn't for some reason this be done in oryginal helper?

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-view; a new issue has been opened at laminas/laminas-view#22.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants