Zend url and custom routes?

I can’t figure it out. How do you use custom URL helper?

I have a method in my users controller called edit , and I have my own route for it, so it can be called via 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 on the main page, but as soon as I am on the settings page, every other link generated by the sub-URL refers to the current url (domain.com/settings)

Any ideas how to fix this?

+4
source share
1 answer

The solution is to add a name to your own 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 in the frontend, add the name of the route:

 <li><a href="<?php echo $this->url(array('controller' => 'users', 'action' => 'edit'), 'settingsPage', true); ?>">Settings</a></li> 

a

+6
source

Source: https://habr.com/ru/post/1333746/


All Articles