Search code examples
phpzend-frameworklazy-loadingzend-navigation

Zend Framework: Initializing Navigation in the Bootstrap


I currently initialize my web site navigation during bootstrap. I initialize anywhere from 1 to 3 navigation objects. Most requests will need the Navigation objects, but some don't. The ones that don't include files generated for download and JSON requests. I don't want to do the work of generating the navigation objects when they aren't going to be used.

I see two different possible solution types:

  1. Specify routes that don't need the navigation, and check those during bootstrap
  2. Lazy-load the navigation

For an acceptable solution I am looking for specifics in solving this problem. I am interested in solution types that I haven't listed as well.


SOLUTION

I am accepting FinalForm's answer, but it did not have the specifics that I was looking for. Here are the steps I took:

  1. Created one lazy loading function in my Navigation database model class for each navigation object
  2. Moved the corresponding Bootstrap code to each of the functions
  3. Added an instance of my Navigation model to Zend_Registry in the Bootstrap
  4. Changed View references like $this->siteNav to Zend_Registry::get('nav')->getSiteNav()

Solution

  • Lazy Load all the way dude.

    • Initializing navigation at boot strap seems like added overhead to the entire application as not every page needs navigation.

    • mucking with Specify routes that don't need the navigation sounds clugey.

    You should extend the Zend Libraries to create your own sorta version library, e.g. extend the core controller. In that extension use that to add a method to build your navigation. In other words subclass your actual application from the extended library classes.

    Or create custom view helpers to develop your navigation.