我使用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
}
}
答案 0 :(得分:0)
我决定使用插件来实现这种细粒度的功能,因为无法正确管理执行顺序,因此使模块引导成为放置具有依赖关系的代码的不良选择。
使用下面引用的答案来做出我的决定:
load /execute module based bootstraps from each module in certain order
答案 1 :(得分:0)
根据ZF1邮件列表中的this thread,您可以通过应用程序引导程序的模块资源访问module-bootstraps。
男人,多么满口。这就是我的意思:// 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
}
}
根据我自己的经验,只要我的一个模块级资源需要在多个模块中引用 - 特别是在引导期间 - 我只需将该资源的引导推送到应用程序级引导程序。