Programmer's Reference Guide

Zend_Navigation

Introduction

Zend_Navigation is a component for managing trees of pointers to web pages. Simply put: It can be used for creating menus, breadcrumbs, links, and sitemaps, or serve as a model for other navigation related purposes.

Pages and Containers

There are two main concepts in Zend_Navigation:

Pages

A page (Zend_Navigation_Page) in Zend_Navigation – in its most basic form – is an object that holds a pointer to a web page. In addition to the pointer itself, the page object contains a number of other properties that are typically relevant for navigation, such as label, title, etc.

Read more about pages in the pages section.

Containers

A navigation container (Zend_Navigation_Container) is a container class for pages. It has methods for adding, retrieving, deleting and iterating pages. It implements the » SPL interfaces RecursiveIterator and Countable, and can thus be iterated with SPL iterators such as RecursiveIteratorIterator.

Read more about containers in the containers section.

Note: Zend_Navigation_Page extends Zend_Navigation_Container, which means that a page can have sub pages.

Separation of data (model) and rendering (view)

Classes in the Zend_Navigation namespace do not deal with rendering of navigational elements. Rendering is done with navigational view helpers. However, pages contain information that is used by view helpers when rendering, such as; label, CSS class, title, lastmod and priority properties for sitemaps, etc.

Read more about rendering navigational elements in the manual section on navigation helpers.


Zend_Navigation

Comments

Ignore EVERYTHING up there. It's CRAP. This is what you're after:

Copy and paste this (1.11)

/application/configs/navigation.xml
--------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<nav>

<home>
<label>Home</label>
<controller>index</controller>
<action>index</action>
</home>

<user>
<label>Users</label>
<controller>user</controller>
<action>index</action>

<pages>
<login>
<label>Login</label>
<controller>index</controller>
<action>index</action>
</login>
<register>
<label>Register</label>
<controller>register</controller>
<action>index</action>
</register>
</pages>
</user>

</nav>
</configdata>


/application/Bootstrap.php
-------------------------------------------------

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

protected function _initNavigation()
{

$this->bootstrap("layout");
$layout = $this->getResource('layout');
$view = $layout->getView();

$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml','nav');
$navigation = new Zend_Navigation($config);

$view->navigation($navigation);

}

}


application/layouts/scripts/layout.phtml
---------------------------------------------------------

<!DOCTYPE html>
<html>
<head>
<?php echo $this->headTitle() ?>
<?php echo $this->headMeta() ?>
<?php echo $this->headScript() ?>
<?php echo $this->headStyle() ?>
</head>
<body>
<?php echo $this->navigation()->menu()->setMaxDepth(1); ?>
<?php echo $this->layout()->content; ?>
</body>
</html>



Bing, bang, boom. This is ALL anyone wanted to come here for.
Thank you Dominic!
You spoke from my soul.

+ Add A Comment

Please do not report issues via comments; use the ZF Issue Tracker.

If you have a JIRA/Crowd account, we suggest you login first before commenting.

  • BBCode is allowed in the comment markup

  • Select a Version

    Languages Available

    Components

    Search the Manual