更新时间:2021-11-28 06:51:37
更改您正在侦听的事件.
Change the event you're listening for.
在这种情况下,我会将这个逻辑移到应用程序引导事件或应用程序渲染事件(我没有测试过,但它可能会正常工作).
In this case, I'd move this logic to the application bootstrap event or the application render event (I haven't tested this, but it would probably work fine).
一个例子,在你的 Module.php 中
One example, in your Module.php
public function onBootstrap($e)
{
$config = $e->getApplication()->getServiceManager()->get('config');
//$e->getViewModel()->setVariable();
}
尚未测试该注释掉的行,但它应该能让您朝着正确的方向前进.
Haven't tested that commented out line, but it should get you headed in the right direction.
找到使用渲染事件的示例
Found an example of using the render event
public function onBootstrap($e)
{
$event = $e->getApplication()->getEventManager();
$event->attach('render', function($e) {
$config = $e->getApplication()->getServiceManager()->get('config');
$e->getViewModel()->setVariable('test', 'test');
});
}