Zend Framework navigation with breadcrumbs

I am able to create my navigation and breadcrumbs in a better way. Using an XML file makes more sense than using an array. It is easier to maintain and edit.

To do this, you first create an XML file. It makes more sense to create your XML file inside the configs directory. So create an XML file in:


The data in the XML file should look like this:

<?xml version="1.0" encoding="UTF-8"?>
                        <label>Categories sitemap</label>
                        <label>Products sitemap</label>

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);

What we are doing here is that we are simply loading the XML file (as an array) into the $view object. We are doing this so that we can access the Zend_Navigation object in our layout/views.

Final Steps
Lastly, you will need to open up your layout file and add these lines:

        <div id="menu">
            <?php echo $this->navigation()->menu(); ?>
        <div id="breadcrumbs">
            You are in: <?php echo $this->navigation()->breadcrumbs()->setLinkLast(false)->setMinDepth(0)->render(); ?>
        <div id="content">
            Content of your page here.

One thought on “Zend Framework navigation with breadcrumbs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s