Zend Framework:在 Bootstrap 中初始化导航
我目前在引导期间初始化我的网站导航。我在任何地方初始化 1 到 3 个导航对象。大多数请求都需要导航对象,但有些则不需要。不包含为下载和 JSON 请求生成的文件。我不想在不使用导航对象时进行生成导航对象的工作。
我看到两种不同的可能解决方案类型:
- 指定不需要导航的路线,并在引导期间检查这些路线
- 延迟加载导航
对于可接受的解决方案,我正在寻找解决此问题的具体。我对尚未列出的解决方案类型感兴趣。
解决方案
我接受FinalForm的答案,但它没有具体细节 我正在寻找。以下是我采取的步骤:
- 创建一个 lazy在我的
Navigation
数据库模型类中为每个导航对象加载 函数 - 将相应的 Bootstrap 代码移动到每个函数
- 将我的
Navigation
模型的实例添加到Bootstrap 中的Zend_Registry
- 将
View
引用(如$this->siteNav
)更改为Zend_Registry::get('nav')-> ;getSiteNav()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一直延迟加载老兄。
在引导带初始化导航似乎增加了整个应用程序的开销,因为并非每个页面都需要导航。
使用
指定不需要导航的路线
进行清理听起来很笨拙。您应该扩展 Zend Libraries 以创建您自己的某种版本库,例如扩展核心控制器。在该扩展中,使用它来添加构建导航的方法。换句话说,您的实际应用程序是从扩展库类中子类化的。
或者创建
自定义视图助手
来开发您的导航。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.