ZF2第二轮自举

时间:2014-03-03 18:26:30

标签: php zend-framework2

我如何能够以某种方式订阅事件,以便在我的某个模块中进行第二轮引导,确保所有模块都已调用其onBootstrap()方法?

我已尝试在我的模块onBootstrap()内订阅相同的onBootstrap()事件,但优先级较低。那没用;显然,在触发任何事件之前确定要触发的事件,因此您无法订阅当前正在触发的相同事件并期望它能够正常工作。

我还想尝试在loadModules.post内订阅init(),然后订阅EVENT_BOOTSTRAP,但我发现我找不到任何方式来访问$mvcEvent反过来,$application,以及需要进行订阅的应用程序事件管理器。

1 个答案:

答案 0 :(得分:2)

前几天我不得不这样做。

您在onBootstrap事件中无法附加,您需要在init方法中附加一个侦听器,而您需要使用共享管理器听取应用程序触发的MvcEvent

public function init(ModuleManager $modules)
{
    // attach to the end of the bootstrap event
    $modules->getEventManager()
            ->getSharedManager()
            ->attach('Zend\Mvc\Application', MvcEvent::EVENT_BOOTSTRAP, function ($e) {
                 // do something after everything else has bootstrapped

             }, -1000);
}