문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top