Zend Navigation Uri and BaseUrl
-
30-04-2021 - |
Question
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.
OTHER TIPS
If you are using the standard way of generating URLs, you can set the base url before generating them as explained here.
http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.rewritebase
$request->setBaseUrl('/project/public/');