How to create Menus and Breadcrumbs in Zend Framework using the Config .ini File CodeUnit 30 MAR 2011

To create navigation menu items in the Zend Framework by storing all the information in your config application.ini file turns out to be a relatively simple affair.

First add the following line to your application.ini file:[] = 

Next define your pages as follows:

resources.navigation.pages.home.label = "Home"
resources.navigation.pages.home.controller = "index"
resources.navigation.pages.home.action = "index"

resources.navigation.pages.item2.label = "Next Item"
resources.navigation.pages.item2.controller = "nextitem"
resources.navigation.pages.item2.action = "index"

;for modules try:
resources.navigation.pages.home.label = "Home"
resources.navigation.pages.home.module = "admin"
resources.navigation.pages.home.controller = "index"
resources.navigation.pages.home.action = "index"

;for sub menu items:
resources.navigation.pages.home.pages.sub.label = "Sub1"
resources.navigation.pages.home.pages.sub.controller = "sub"
resources.navigation.pages.home.pages.sub.action = "index"

Now that your pages have been defined, your bootstrap file can be used to initiate the layout, which in turn initiates the navigation object automatically. If you check your bootstrap file, you should have a function looking something like this:

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

Finally, to actually print out the navigation menu in your layout, simply add the following line somewhere in your layout.phtml file:


As easy as that.

Note that if you want breadcrumbs in your layout, you can use this:

echo $this->navigation()->breadcrumbs()


About Craig Lotter

Software developer, husband and dad to two young ladies. Writer behind An Exploring South African. I don't have time for myself any more.