开发者

How to strip unused parameters from the url?

I'm using Zend Framework and the URL View Helper to create URLs

I have some lines like this in my navigation:

$this->url(array('controller' => 'index', 'action' => 'index'))
$this->url(array('controller' => 'who', 'action' => 'view', 'id' => $row->who_id));
$this->url(array('controller' => 'projects', 'action' => 'view', 'id' => $row->mai_id));
$this->url(array('controller' => 'content', 'action' => 'view', 'type' => 'theater', 'id' => $row->the_id));
$this->url(array('controller' => 'shows', 'action' => 'view'));

This way, at first, I have some URL like this

http://ccgss.local/information/location
http://ccgss.local/who/view/id/1

But when I access another link with more parameters like http://ccgss.local/content/view/id/1/type开发者_运维技巧/theater it messes up with the parameters that still were there: http://ccgss.local/who/view/id/1/type/theater

I mean, the parameters don't clean up when I access another page.

How do I fix this?


You need to reset parameters when calling url helper.

$this->url(array('controller' => 'index', 'action' => 'index'), null, true);

The second argument is the name of the route to use. Keep it null if you want to use the current route.
The third argument tells whether or not to reset parameters. It's false by default. So, just set it to true to get rid of existing parameters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜