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


Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.

  • Jorge

    Do you have any example using menu, acl`s and modules? I mean… I want to show the menu according to module… I hope you can help me…

  • Matthew

    How can you use this method to create a whole new menu?

    • I don’t know. Still busy learning the basics of Zend… slowly.