Zend Framework navigation with breadcrumbs

It’s been a while since I last time played with beauty of Zend Framework.

Each time I check new features it seems to me that the things are more simplier than the last time,
I might be wrong (I wouldn’t bet on that) or I’m just getting better 🙂

Let’s check this piece of cake – how you can create navigation with breadcrumbs in Zend Framework project.
As many things in Zend Framework you can get same features in different ways,
so the same thing goes with the Zend_Navigation class.

First of all you need to decide which way you will choose:
– navigation with xml setup file or
– from application.ini file

I suggest you to try both ways and then choose the one you like most, I’ll show you the both ways.

In Boostrap.php class you need to initialize your navigation.
– xml way tells where your navigation.xml file is:

protected function _initNavigationXml()
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml');
$navigation = new Zend_Navigation($config);

– or in “config” way from application.ini file you simply tell your Bootstrap class which part needs to be processed:

protected function _initNavigationConfig()
$layout = $this->getResource('layout');
$view = $layout->getView();
$navigation = new Zend_Navigation($this->getOption('navigation'));

Now you have setup your configuration for navigation, next thing you need to do is in your
application/layouts/layout.phtml file call the data you insert into your application.ini or navigation.ini files, you do that with this line of code:

< ?php
echo $this->navigation()->menu();

For desert you can add breadcrumbs into same file like this:

< ?php
echo $this->navigation()->breadcrumbs()

At the end you get something like on picture below:

Here is full featured project zf.navigation.sample (without Zend Framework, which you need to copy in library folder) to download.

Enjoy coding.

You made it all the way down here so you must have enjoyed this post! You may also like:

Using Redis cache backend and session storage in Magento Marko Martinovic
Marko Martinovic, | 43

Using Redis cache backend and session storage in Magento

Consuming Magento REST service using Zend_OAuth_Consumer Darko Goles
Darko Goles, | 45

Consuming Magento REST service using Zend_OAuth_Consumer

Unit testing with Zend framework: Setting up environment for the first test using Netbeans IDE for php Darko Goles
Darko Goles, | 1

Unit testing with Zend framework: Setting up environment for the first test using Netbeans IDE for php


  1. i am using to generate dynamic url paths like i have city controller and city action. In that city action i have dropdown with city names. When i change cityname in city dropdown , i generated url with cityname(Ex:public/india-properties or us-properties), but controller and actions are same. So want dynamic city name based navigation can you try once.

  2. Harish

    You can replace the method htmlify
    with class extends
    Zend_View_Helper_Navigation_Menu and setting your helper path.

  3. This post was super helpful. I didn’t know making navigation elements were so easy in Zend Framework. I think the hardest part of this may be to make the XML file. I’ll share this and take a look at your other posts.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.