Default_Bootstrap 覆盖 Admin_Bootstrap [英] Default_Bootstrap overrides Admin_Bootstrap
问题描述
在管理模块安装默认模块的布局和导航
In the Admin module installation Layout and Navigation of Default module
application/modules/default/Bottstrap.php
application/modules/default/Bottstrap.php
<?php
class Default_Bootstrap extends Zend_Application_Module_Bootstrap
{
protected function _initNavigation()
{
$layout = Zend_Layout::startMvc()->setLayout('layout');
$config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml','nav');
$navigation = new Zend_Navigation($config);
Zend_Registry::set('Zend_Navigation', $navigation);
}
}
application/modules/admin/Bottstrap.php
application/modules/admin/Bottstrap.php
<?php
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{
protected function _initNavigation()
{
$layout = Zend_Layout::startMvc()->setLayout('admin');
$config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navadmin.xml','nav');
$navigation = new Zend_Navigation($config);
Zend_Registry::set('Zend_Navigation', $navigation);
}
}
application/configs/application.ini
application/configs/application.ini
;Modules
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.defaultModule = "default"
resources.modules[] =
resources.frontController.actionhelperpaths.Default_Controller_Helper = APPLICATION_PATH "/modules/default/controllers/helpers"
;Layout
resources.layout.layoutpath = APPLICATION_PATH "/layouts"
;View
resources.view.doctype = "HTML5"
resources.view.encoding = "UTF-8"
resources.view.contentType = "text/html; charset=UTF-8"
推荐答案
在单模块应用程序中,布局和导航通常在单个应用程序级引导程序中初始化(有时通过引用应用程序资源插件).
In a single-module application, layout and navigation are typically initialized in the single app-level bootstrap (sometimes by reference to an application resource plugin).
>
但是,在多模块应用程序中,所有模块引导程序都将运行.因此,最后一个运行的最终会覆盖所有其他的.
However, in a multi-module application, all the module bootstraps will run. Therefore, the last one that runs ends up overriding all the others.
对于这些类型的任务,需要知道请求了哪个模块,您可以使用带有 routeShutdown()
钩子的前端控制器插件.每个模块 X 都可以注册自己的导航和布局插件,以检查请求的模块是否与 X 匹配.如果不匹配,请尽早退出.如果是,请执行初始化.
For these types of tasks that depend upon knowing which module has been requested, you can use a front-controller plugin with routeShutdown()
hook. Each module X could register its own plugins for navigation and layout that check if the requested module matches X. If not, bail early. If so, perform your initialization.
有关更多详细信息,请参阅 MWOP 关于模块引导主题的文章:
See MWOP's article on the subject of module bootstrapping for more details:
http://mwop.net/blog/234-Module-Bootstraps-in-Zend-Framework-Dos-and-Donts
这篇关于Default_Bootstrap 覆盖 Admin_Bootstrap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!