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:
- Specify routes that don't need the navigation, and check those during bootstrap
- 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:
- Created one lazy loading function in my
Navigation
database model class for each navigation object - Moved the corresponding Bootstrap code to each of the functions
- Added an instance of my
Navigation
model toZend_Registry
in the Bootstrap - Changed
View
references like$this->siteNav
toZend_Registry::get('nav')->getSiteNav()