Question

I am using Zend Framework 1.12.

I wanted to add some routers. There are users and administrators in my system, and I have added a router for administrator viewing user's page.

I added

// meant to create the usage "xxx.com/userview/someusername"
    $route = new Zend_Controller_Router_Route(
            'userview/:username',
            array('controller' => 'user',
                'action' => 'viewone',
                'username' => 'someusernamedefault')
            );
    $router = $frontController->getRouter();
    $router->addRoute('userview', $route);

to my Bootstrap.php file. I had some links in my sidebar, which contains links to actions (of another controller). I had added their link in a .phtml file as

echo $this->url(array('controller'=>'somecontroller', 'action'=>'someaction' ), null, true);

This sidebar contains lots of this links, which are from multiple controllers.

These worked fine till I added the route. After I added new route to Bootstrap (and added new action (viewall) to that controller (user) which is pointed from rooter, that works fine (I can use as "xxx.com/userview/someusername ). But my other links in the sidebar all becomes "xxx.com/userview". They all lose their values of controller and action...

What am I doing wrong?? Should I define my url's better, or my router better?

Thanks in advance.

Was it helpful?

Solution

The second param to the URL helper should be the name of the route you want to use. By passing null you're telling it to use the current route, which is why the links are coming out wrong. Change your sidebar link calls to:

$this->url(array('controller'=>'somecontroller', 'action'=>'someaction'), 'default');

and then it should work fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top