Zend Framework navigation with breadcrumbs

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()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml');
 
$navigation = new Zend_Navigation($config);
$view->navigation($navigation);
}

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

protected function _initNavigationConfig()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
 
$navigation = new Zend_Navigation($this->getOption('navigation'));
$view->navigation($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()
->setLinkLast(false)->setMinDepth(0)->render();
?>

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

Using Redis cache backend and session storage in Magento

Consuming Magento REST service using Zend_OAuth_Consumer Darko Goles
Darko Goles

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

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

Tell us about your project

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