I'm having an issue with my routes.
So let's say I have the TestController with the action edit , that gets a parameter named as 'name'.
The access url would be test.com/test/edit/name/randomname .
I wanted to make it so it could be accessed by test.com/test/edit/randomname , so I added this in the function _initRoutes in Bootstrap.
$router = Zend_Controller_Front::getInstance()->getRouter();
$route = new Zend_Controller_Router_Route(
'test/edit/:name',
array('controller' => 'test', 'action' => 'edit', 'name' => 'Default'));
$router->addRoute('edit-test', $route);
So it works as I want it to, but another issue occurred. I have a link in the layout.phtml which is something like
<a href="<?php echo $this->url(array('controller' =>'account','action'=>'logout'));?>">Logout</a>
The problem is that when i navigate to test.com/test/edit/randomname , the link above for some weird reason changes and points to the same url as above, ie test.com/test/edit/randomname .
What's going wrong?
Note: Im using modules, the TestController is in the default module.
In the past, I have had to specify the route to use with the url()
view-helper. Since your logout route seems to use the default route, specify it in the url()
invocation:
<a href="<?php
echo $this->url(array(
'controller' =>'account',
'action' =>'logout'
), 'default'); ?>">Logout</a>
If you don't explicity specify the route, then the current route gets used, which in your case is probably the edit-test
route.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.