Zend Created route and now all links use this url

412 views Asked by At

I created a route to view users profiles:

$router = Zend_Controller_Front::getInstance()->getRouter();
    $route  = new Zend_Controller_Router_Route(
            'profile/:username',
            array(
                'username'      => 'username',
                'module'        => 'core',
                'controller'    => 'profile',
                'action'        => 'view'   
            ) 
    );
    $router->addRoute('profile',$route);

When I go there, all of the urls within the page all now say http://127.0.0.1/project/public/profile.

How do I fix this?

2

There are 2 answers

0
Phil On BEST ANSWER

If using the Url view helper or Zend_Navigation, you need to specify the route to use if you don't want it to use the current one. For example...

Url view helper

Use the "default" route

<?php echo $this->url(array(
    'action'     => 'index',
    'controller' => 'index'
), 'default', true) ?>

Navigation config

resources.navigation.pages.home.label      = "Home"
resources.navigation.pages.home.action     = "index"
resources.navigation.pages.home.controller = "index"
resources.navigation.pages.home.module     = "default"

; Don't forget to set the route
resources.navigation.pages.home.route      = "default"

Addendum

The easiest way to configure routes is via the Router resource. Try this in your configuration instead of the code you have

resources.router.routes.profile.route               = "profile/:username"
resources.router.routes.profile.defaults.module     = "core"
resources.router.routes.profile.defaults.controller = "profile"
resources.router.routes.profile.defaults.action     = "view"
0
gwena On

Thanks Phil ! I had the same problem and you saved me ;)

Just for information, for people who use the xml structure for Zend Navigation, just add for each routes.

For exemple :

<?xml version="1.0" encoding="UTF-8"?>
    <configdata>
        <nav>
            <myfirstroute>
                <label>...</label>
                <module>...</module>
                <controller>...</controller>
                <action>...</action>
                **<route>default</route>**
            </myfirstroute>

            <mysecondroute>
                <label>...</label>
                <module>...</module>
                <controller>...</controller>
                <action>...</action>
                **<route>default</route>**
            </mysecondroute>
            ...
        </nav>
    </configdata>

See you !