Default_Bootstrap overrides Admin_Bootstrap

2019-06-10 08:07发布

问题:

In the Admin module installation Layout and Navigation of Default module

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

<?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

;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"

回答1:

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.

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.

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



回答2:

a technique of loading a program into a computer by means of a few initial instructions which enable the introduction of the rest of the program from an input device. start up (an Internet-based business or other enterprise) with minimal financial resources.