first I'd like to admit I didn't do enough searching about this mainly because I didn't know how to put it in words fit for the search. is it 'getting clean urls in zend' or 'ignore what comes after the action in zend' I really can't name it well, so deeply sorry for this. guide me for duplicates, I'll delete this at once :>
now, story goes like this:
let's say in pageproject/public/home
I've got a link
<a href="<?php
echo $this->url(array(
'controller' => 'test',
'action' => 'index'
));
?>
">
<?php echo $this->translate('go_to_test_index'); ?>
</a>
that would get me to project/public/home/test/index
(index omitted by default)
let's say another link with parameter
<a href="<?php
echo $this->url(array(
'controller' => 'message',
'action' => 'add',
'id' => 1//some value or another parameter
));
?>
">
<?php echo $this->translate('go_to_add_message'); ?>
</a>
that would take me to project/public/home/message/add/1
till now I understand perfectly but the issue appears when I try to go back
<a href="<?php
echo $this->url(array(
'controller' => 'test',
'action' => 'index'
));
?>
">
<?php echo $this->translate('back'); ?>
</a>
as far as I know that should take me to project/public/home/test/index
but instead I get project/public/home/test/index/id/1
(index not omitted) the test/index page is displayed but that id parameter is just wrong to be there
what is the proper name of this problem? what's causing it? am I missing some parameter of url
? any pointers on how to fix it?
thanks a lot in advance
duplicate of Stackoverflow question
documentation referenced there Zend View Helpers
Use the reset option in the Url View Helper as shown below.
<a href="<?php
echo $this->url(array(
'controller' => 'test',
'action' => 'index'
), null, true);
?>
">
<?php echo $this->translate('back'); ?>
</a>
And here are few more tips for generating Urls.
Hope this helps.
As @Jay Bhatt mentioned, there is a reset
param which is defaulted to false.
Set it to true
if you want to reset all current request params in the new generated link.
<a href="<?php
echo $this->url(
array('controller' => 'test', 'action' => 'index'),
null,
true
);
?>"><?php echo $this->translate('back'); ?></a>
Note that if you want to reset only one param, you can set it as null
<a href="<?php echo $this->url(array(
'controller' => 'test', 'action' => 'index', 'id' => null
));
?>"><?php echo $this->translate('back'); ?></a>
Hope it helps