Search code examples
zend-frameworkzend-viewzend-navigationview-helpers

Zend Navigation Uri and BaseUrl


I am setting up zend navigation in my website and I've got a issue while developing locally.

My navigation.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
 <nav>
    <page1>
        <label>Site</label>
        <uri>/</uri>
        <pages>
            <page1_1>
                <label>Home</label>
                <uri>/</uri>
            </page1_1>
            <page1_2>
                <label>Contact</label>
                <uri>/contact</uri>
            </page1_2>
        </pages>
    </page1>
  </nav>
</config>

Rendering the menu

<?=$this->navigation()->menu();?>

HTML Output

<ul class="navigation">
 <li class="active">
    <a href="/">Site</a>
    <ul>
        <li>
            <a href="/">Home</a>
        </li>
        <li class="active">
            <a href="/contact">Contact</a>
        </li>
    </ul>
 </li>

I develop the project in a subfolder Ex.: http://localhost/project/public. And zend navigation uri shows link as http://localhost/contact instated of http://localhost/project/public/contact

How could I apply my baseUrl over uri?


Solution

  • you can specify the whole route in your xml file:

        <home>
            <label>Home</label>    
            <route>home</route>
            <module>default</module>
            <controller>index</controller>
            <action>index</action>
        </home>
    

    this is a named route as well as specified by module, controller, action.