0

In the Zend framework, I am using the $this->url() method and it's working like a charm. I have one problem though: the method seems to copy the current request parameters over to the new URL. I want it to stop doing this.

An example: I use $this->url('controller' => 'blog', 'action' => 'list');. If the current page is www.foo.bar/item/view/id/1 with id being a parameter, the URL will become:

www.foo.bar/blog/list/id/1

You can see the /id/1 part is retained without me specifying it.

How can I make it stop doing this? Thanks in advance.

bizzehdee
  • 20,289
  • 11
  • 46
  • 76
Neko
  • 3,550
  • 7
  • 28
  • 34
  • There's another discussion similar to this.. Might be helpful : http://stackoverflow.com/questions/993725/removing-parameters-from-url-when-using-url-view-helper-links – J A Mar 16 '13 at 19:45

2 Answers2

2

Please refer to this duplicate question, it's on an older version of ZF, but it should point you in the right direction:

Zend url : get parameter always stay in the url

Community
  • 1
  • 1
gmartellino
  • 697
  • 5
  • 16
  • Thanks! I knew there had to be something like this. Apologies for the redundant question. – Neko Mar 16 '13 at 19:38
1

Set any parameter you don't want to keep to null:

$this->url('controller' => 'blog', 'action' => 'list', 'id'=>null);

EDIT There is one more way. In fact, all url helpers does is a pass through call to router:

 public function url(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
        {
            $router = Zend_Controller_Front::getInstance()->getRouter();
            return $router->assemble($urlOptions, $name, $reset, $encode);
        }

As you can see, the third parameter (boolean $reset) should reset any parameters stored in the current route. Assuming you are using the standard router (Zend_Controller_Router_Rewrite) the call will be passed to a route (possibly some descendant of Zend_Controller_Router_Route), and should be interpreted as such. Of course if you use your own Route, you should take care of this yourself.

fdreger
  • 12,264
  • 1
  • 36
  • 42
  • Is this the only way? There may be any number of parameters used throughout the website. It would be a bit annoying to have to check for them all every time. – Neko Mar 16 '13 at 19:31
  • there is some switch (that I don't remember) that clears the parameters, but if you only need to remove id, this way is shorter :-) I will add an edit. – fdreger Mar 16 '13 at 19:38