1

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
    }
}
4

2 回答 2

0

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

使用下面的参考答案来确定我的决定:

以特定顺序从每个模块加载/执行基于模块的引导程序

于 2013-04-09T00:31:38.837 回答
0

根据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
    }
}

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

于 2013-04-09T03:01:20.933 回答