Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to implement breadcrumbs using Zend_Navigation

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?

like image 756
farzad Avatar asked Dec 18 '22 07:12

farzad


2 Answers

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.

like image 116
Stefan Gehrig Avatar answered Dec 28 '22 06:12

Stefan Gehrig


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.

like image 23
wenbert Avatar answered Dec 28 '22 07:12

wenbert