This tutorial covers a lot of the basic use cases with Zend_Navigation. Using a uri-based navigation.xml file, we generate a very simple menu system as well as a breadcrumb with some basic information. In the last 3 minutes I cover how to get a Google compliant sitemap from the navigation.xml file. This video is by no means exhaustive, but should get you up and running with Zend_Navigation in the Zend Framework.
Browse the code off google code or download a zip here.
On another note, I’m thinking of putting together a forum as a way of organizing some of the informative discussion I’ve found in the comments section. I know other forums exist so I’d be curious to know if you think zendcasts would benefit from such a thing.
Alternatively, if you have topics you’d like covered and are willing to step up to the mic, I’d love to share your own screencasts with the now over 550 subscribers!

Hi Jon,
the last days I ran into trouble because of some faulty code in your _initNavigation():
$this->bootstrap(‘layout’);
$layout = $this->getResource(‘layout’);
->getView();
Hi Jon,
the last days I ran into trouble because of some faulty code in your _initNavigation():
$this->bootstrap(‘layout’);
$layout = $this->getResource(‘layout’);
$view = $layout->getView();
led to the problem that another view renderer was created and I had to write some addHelper() code into the Bootstrap.php for other view helpers, having these in the layout available.
This code fixed the problem:
$this->bootstrap(‘view’);
$view = $this->getResource(‘view’);
The issue is further discussed in the forum:
http://www.zendcasts.com/forum/post/1179/#p1179
Regards,
Sven
First : Thank you soooo much !
You gave me exactly what I wanted.
Take time to come in my website and give me your opinion…
See you soon and thanks again,
Pat
Fantastic!!! Not only does it give a great idea about Zend_Navigation, but also is helpful in creating breadcrumbs and sitemaps and disabling the standard layout – I learned a lot from this. Thanks Jon!
I had trouble adding the “about” and “contact” actions/views. I followed everything in this tutorial perfectly but when clicking links for about and contact I always got errors that it wasn’t found. In case it happens to anyone else, I found the solution in the ZF Quickstart guide. Create a virtual host by adding this to your httpd.conf file:
ServerName quickstart.local
DocumentRoot /path/to/quickstart/public
SetEnv APPLICATION_ENV “development”
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
In ‘application/config.ini’:
…
resources.frontController.plugins.Navigation = “APP_Controller_Plugin_Navigation”
…
In ‘library/App/Controller/Plugin/Navigation.php’:
initView();
$view = $viewRenderer->view;
$uri = $request->getPathInfo();
$activeUri = $view->navigation()->findByUri($uri);
$activeUri->active = true;
$html = $view->navigation()
->breadcrumbs()
->setMinDepth(0)
->setLinkLast(true)
->setSeparator(‘ > ‘);
}
}
Believe that this could help ;]
sorry for posting under post but please delete this and my last post because ive pase wrong pice of code… sorry for that.
i am having problems with breadcrumbs and i am getting “Strict standards”.
when i do:
$activeNav = $this->view->navigation()->findByUri($uri);
var_dump( $activeNav);exit;
I am getting “null”.
Can somebody help me on this?
Thx
Cool! Thanks.
Thanks Jon this ZendCast rocks!
I have the same trouble than memo23,
I am having problems with breadcrumbs and i am getting “Strict standards”.
when i do:
$activeNav = $this->view->navigation()->findByUri($uri);
var_dump( $activeNav);exit;
I am getting “null”.
Can somebody help me on this?
Thanks
Hey man great tutorial!!!!
thx you really helpfull
Jon,
Thank you, It works great! Can you help me edit the standard, or at least point me in the right direction?
I need to customise the bread crumbs css/class name and have it render slighly diffrently…
Non active link or the separator
Active link
at the moment it renders with a class name of “breadcrumbs”..
hope this makes sence!
oh, html tags on…
So this is how I need to display the breadcrumbs…
[code]
<!-- No link page title or seperator -->
<!-- Link -->
[/code]
Is thee any cast about dinamicaly creating menus, pages in Zend FW?
that would be nice to know how to make.
Is it possible at all?
Thanks for this cast, its pretty much straght forward and easy to make.
But i would like to know about how to create not hardcoded menu.
Create a page with a form, add new menu item in database, and then add some content to that menu page.
Thanks for your video tho
Thank you Jon, Great Tutorial!!
Thanks! That was very very useful!
Dovla: you can always create array for dynamic navigation creation. This should help:
http://framework.zend.com/manual/en/zend.navigation.containers.html
getting an error on new Zend_Navigation($config) running ZF 1.11
Fatal error: Uncaught exception ‘Zend_Navigation_Exception’ with message ‘Invalid argument: Unable to determine class to instantiate’
Zend_Navigation->__construct(Object(Zend_Config_Xml))
Thank you so much for this – its a supurb tutorial – one of tebest ive seen on zend
@zorf:
I got the same error… you probably have not nested inside
structure should be
…
Once it’s inside the node, it should work fine.
Hi Everyone,
Take a look on my website, I’ve used zend navigation with all source code on it.
Bye
DouDoy
Hi,
I just followed your video on the zend menus, breadcrumbs and sitemap. I thought I wrote something wrong as I followed the video so I downloaded the zip files and move them to my localhost but I couldn’t see the menu. Same thing I got when I followed the videos. Is there something I missing? I am using the latest ZendFramework platform. Any ideas would be greatly appreciated.
Regards,
Carlos
I’m using XAMPP with Zend Framework 1.11.8 on Mac OS X (Snow Leopard). This tutorial worked out fine for me, except that I had to make a couple of changes, which others too may encounter.
I called my web site “flix” for the tutorial, and I didn’t set up a virtual host. For this reason, I had to prepend ‘/flix/public’ to the URIs that were added in the navigation.xml file.
About
/flix/public/index/about
Then, in order for the breadcrumbs to work, I had to do the same thing, for the init() function in the IndexController as follows:
public function init()
{
$uriPrepend = ‘/flix/public’;
$uri = $this->_request->getPathInfo();
$activeNav = $this->view->navigation()->findByUri($uriPrepend . $uri);
$activeNav->active = true;
}
This got everything working for the tutorial with my setup.
I was confused about where the findByUri() function came from, until I read this page http://framework.zend.com/manual/en/zend.navigation.containers.html, and learning that the findByUri() function is really a “magic” function call. Scroll down to the section called “Finding Pages” on that site.
No doubt, others will have the same problems that I had, so I hope this helps.
To the author, thanks for the zendcasts!
Steven
Nice cast!! It was very very helpfull!! Thanks a lot for putting it together!
Hi everyone !
have a look on my website !
Bye
hello, very good video, now a question as I can add a class to the second level UL ….
Thank you,
example:
home
users
New
Delete
This is great tutorial however the following line gives blank, shows nothing on screen for zend 1.11
echo $this->navigation()->breadcrumbs()->setMinDepth(0)->setLinkLast(true)->setSeparator(” / “);
Seems like issue stars back in controller from these two lines.
$activeNav=$this->view->navigation()->findByUri($uri);
$activeNav->active=true;
because line before these was giving path correctly.
Please advise if something regarding this changed for 1.11
mine is zend 1.11.11