Reputation:
I can't figure this out. How do you use the url helper with custom routes?
I have a method in my users
controller called edit
and I have a custom route for it so it can be called through domain.com/settings (instead of domain.com/users/edit)
When I use the url helper this way:
<li><a href="<?php echo $this->url(array('controller' => '', 'action' => 'settings')); ?>">Settings</a></li>
it works fine from the main page, but once I het on the settings page, every other link generated by the url helper links to the current url (domain.com/settings)
Any ideas how to fix this?
Upvotes: 4
Views: 4988
Reputation: 214
The solution is to add a name to your custom route.
$router->addRoute(
'settingsPage', //this is the name
new Zend_Controller_Router_Route('settings',
array('controller' => 'users',
'action' => 'edit'))
);
When you go to use it on the frontend, add your route name:
<li><a href="<?php echo $this->url(array('controller' => 'users', 'action' => 'edit'), 'settingsPage', true); ?>">Settings</a></li>
a
Upvotes: 5