代码之家  ›  专栏  ›  技术社区  ›  danronmoon

如何在Zend Framework 1中执行另一个模块的引导程序中存在的模块引导程序资源?

  •  1
  • danronmoon  · 技术社区  · 11 年前

    我正在用引导我的应用程序 Zend_Application_Module_Bootstrap 在各种模块目录中。如何要求首先执行另一个模块的引导程序中的资源?

    // app/modules/user/Bootstrap.php
    class User_Bootstrap extends Zend_Application_Module_Bootstrap
    {
        protected function _initUser()
        {
        }
    }
    
    // app/modules/author/Bootstrap.php
    class Author_Bootstrap extends Zend_Application_Module_Bootstrap
    {
        protected function _initAuthor()
        {
            $this->bootstrap('user'); // Fatal:  Resource matching 'user' not found
        }
    }
    
    2 回复  |  直到 9 年前
        1
  •  0
  •   Community leo1    7 年前

    我决定使用插件来实现这种细粒度的功能,因为无法正确管理执行顺序,因此模块引导对于放置具有依赖关系的代码来说是一个糟糕的选择。

    使用以下参考答案作为我的决定依据:

    load /execute module based bootstraps from each module in certain order

        2
  •  0
  •   David Weinraub    11 年前

    根据 this thread 从ZF1邮件列表中,您可以通过应用程序引导的模块资源访问模块引导。

    伙计,真是一口。我的意思是:

    // app/modules/user/Bootstrap.php
    class User_Bootstrap extends Zend_Application_Module_Bootstrap
    {
        protected function _initUser()
        {
        }
    }
    
    // app/modules/author/Bootstrap.php
    class Author_Bootstrap extends Zend_Application_Module_Bootstrap
    {
        protected function _initAuthor()
        {
            $app = $this->getApplication(); // it's actually the application *bootstrap*
            $app->bootstrap('modules');
            $modulesResource = $app->getResource('modules'); 
            $userBootstrap = $modulesResource->user;
            $userBootstrap->bootstrap('user'); // should be cool
        }
    }
    

    根据我自己的经验,一旦我的一个模块级资源需要在多个模块中引用,尤其是在引导过程中,我只需将该资源的引导推到应用程序级引导中。