4

what are the best practices/suggestions/techniques to implement a breadcrumb for a ZendFramework application using Zend_Navigation? how and where is the best method to define the page hierarchy?

2 Answers 2

7

Getting breadcrumbs is quite easy:

  • register your Zend_Navigation object that you created in your bootstrap (or some other place) in the Zend_Registry with key Zend_Navigation. That way the object will be caught up by all navigation view-helpers.
  • if you're using the new Zend_Application-style bootstrapping you can simply use the Zend_Application_Resource_Navigation resource to setup navigation. Just set resources.navigation.storage.registry = true in your configuration.
  • you can then simply

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

    in your view or layout script.

Talking about how to define the page hierarchy, I'd say that if you have a somehow smaller and more static site, you can simply define the pages within your configuration (when using the new Zend_Application-bootstrapping-approach):

resources.navigation.pages.home.label       = "Home"
resources.navigation.pages.home.action      = "index"
resources.navigation.pages.home.controller  = "index"
resources.navigation.pages.login.label      = "Login"
resources.navigation.pages.login.action     = "login"
resources.navigation.pages.login.controller = "users"
resources.navigation.pages.users.label      = "Users"
resources.navigation.pages.users.action     = "list"
resources.navigation.pages.users.controller = "users"
resources.navigation.pages.users.pages.show.label      = "Show"
resources.navigation.pages.users.pages.show.action     = "show"
resources.navigation.pages.users.pages.show.controller = "users"
...

Alternatively you could use an extra configuration file or you could build your page hierarchy in a front-controller plugin or an action helper, e.g. if you have a fairly large site structure and don't want to instantiate the whole sitemap on each request. That way you can also insert dynamic pages whose labels for example are dynamically created based on the request parameters.

Sign up to request clarification or add additional context in comments.

1 Comment

Great answer. We have a controller plugin that generates the navigation container for the whole site, and caches it for subsequent requests. Definitely recommend the config solution for small sites though.
5

I made 2 posts on this.

http://blog.ekini.net/2009/05/25/zend-framework-making-the-built-in-breadcrumb-helper-work/

http://blog.ekini.net/2009/06/10/zend-framework-navigation-and-breadcrumbs-with-an-xml-file-in-zf-18/

Both are from real world experiences. For me, the XML file was easier to understand.

2 Comments

I found using the Zend_Config_XML and an XML file for navigation config is a smooth way to do this. thanks.
thanks farzad. Although INIs are shorter to write (no closing tags, etc.), I find the XML file simpler to understand and implement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.