Alex Tech Adventures The webs best tutorials!

Welcome, Guest
Please Login or Register.    Lost Password?

Site navigation menu with Zend_Navigation
(1 viewing) (1) Guest
Go to bottomPage: 12
TOPIC: Site navigation menu with Zend_Navigation
#741
Site navigation menu with Zend_Navigation 1 Year, 5 Months ago Karma: 16
** This thread discusses the content article: Site navigation menu with Zend_Navigation **

alexanderrv
Administrator
Posts: 279
graph
User Offline Click here to see the profile of this user
Gender: Male tmthv2 alexchatonly@hotmail.com Location: Freeport, Bahamas Birthdate: 1989-04-14
The administrator has disabled public write access.
 
#742
Re: Site navigation menu with Zend_Navigation 1 Year, 5 Months ago Karma: 1
Hi,

I want to define more then one navigation. So I just dublicate the code and rename some parameters:

Code:

$navContainerConfig2 = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation2.xml', 'nav');
$navContainer2 = new Zend_Navigation($navContainerConfig2);
$view->navigation2($navContainer2)->setAcl($this->_acl)->setRole(Zend_Registry::get('role'));

$navContainerConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$navContainer = new Zend_Navigation($navContainerConfig);
$view->navigation($navContainer)->setAcl($this->_acl)->setRole(Zend_Registry::get('role'));



but I get an error:

Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'Navigation2' was not found in the registry

can you help me?
AD
Junior Boarder
Posts: 24
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#753
Re: Site navigation menu with Zend_Navigation 1 Year, 4 Months ago Karma: 16
$view->navigation() is a view helper function, not a variable so you cannot just say navigatin2 unless you write a view helper plugin called that.
ZF does not support multiple navigations as discussed here
There is a workaround suggested in comment "24/Aug/09 06:17 AM". It involves not assigning navigation to view at bootstrap (and thus not being able to add more late) but instead put Z_Nav objects in Z_Registry and then have the navigation view helper in layout render the navigation based on the Z_Nav objects in Z_Registry.

Bootstrap:
Code:


$navContainerConfig2 = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation2.xml', 'nav'); 
$navContainer2 = new Zend_Navigation($navContainerConfig2);
Zend_Registry::set('nav2', $navContainer2);

$navContainerConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav'); 
$navContainer = new Zend_Navigation($navContainerConfig);
Zend_Registry::set('nav', $navContainer);



Layout
Code:


echo $this->navigation()->menu()->renderMenu(Zend_Registry::get('nav2'))->setAcl()->etc;
echo $this->navigation()->menu()->renderMenu(Zend_Registry::get('nav))->setAcl()->etc;

alexanderrv
Administrator
Posts: 279
graph
User Offline Click here to see the profile of this user
Gender: Male tmthv2 alexchatonly@hotmail.com Location: Freeport, Bahamas Birthdate: 1989-04-14
The administrator has disabled public write access.
 
#754
Re: Site navigation menu with Zend_Navigation 1 Year, 4 Months ago Karma: 1
thank, thats a good way to do it. but how to I get the acl object in the layout?
AD
Junior Boarder
Posts: 24
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#755
Re: Site navigation menu with Zend_Navigation 1 Year, 4 Months ago Karma: 1
hi again. I have found a more better way to manage multiple navigation in my web application.
in /configs in your navigation.xml you can define more then just one navigation. It looks that way:

Code:


<?xml version="1.0" encoding="UTF-8"?>
<config>
<nav>
<menu1>
<label>menu1</label>
<uri>#</uri>
<pages>
<pa>
<label>Index</label>
<resource>default:index</resource>
<module>default</module>
<controller>index</controller>
<action>index</action>
<privilege>index</privilege>
</pa>
</pages>
</menu1>
</nav>
</config>



we can keep the navigation code in bootstrap just like you did it alex:

Code:


$navContainerConfig = new Zend_Config_Xml ( APPLICATION_PATH . '/configs/navigation.xml', 'nav' );
$navContainer = new Zend_Navigation ( $navContainerConfig );
$view->navigation ( $navContainer )->setAcl ( $this->_acl )->setRole ( Zend_Registry::get ( 'role' ) );



in any layout you want to display a navigation you do the following:

Code:


$navPrimary = $this->navigation()->findOneByLabel(menu1');
echo $this->navigation()
                   ->menu()
                   ->renderMenu($navPrimary);



thats all and it works
AD
Junior Boarder
Posts: 24
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#756
Re: Site navigation menu with Zend_Navigation 1 Year, 4 Months ago Karma: 16
So then I can just add
Code:


$navSecondary = $this->navigation()->findOneByLabel(menu2'); 
echo $this->navigation() 
                   ->menu() 
                   ->renderMenu($navSecondary); 


??

Great tip. Thank you for letting me know.
alexanderrv
Administrator
Posts: 279
graph
User Offline Click here to see the profile of this user
Gender: Male tmthv2 alexchatonly@hotmail.com Location: Freeport, Bahamas Birthdate: 1989-04-14
The administrator has disabled public write access.
 
Go to topPage: 12
Moderators: alexanderrv
You are here: Home Forum

Statistics

Members : 1401
Content : 42
Web Links : 1
Content View Hits : 191196

Poll

Interested in TinyBrowser and TinyMce plugin for ZF?
 

Who's Online

We have 48 guests online