【发布时间】:2016-04-07 16:18:06
【问题描述】:
在 config/autoload/global.php 我只有我的数据库的配置。 在我的模型中,我有:
public function __construct($adapter = null)
{
if ($adapter) {
$this->adapter = $adapter;
} else {
... //here I need to get the config without serviceLocator
}
}
public function attach(EventManagerInterface $events)
{
$sharedEvents = $events->getSharedManager();
$this->listeners[] = $sharedEvents->attach("*", "redirect", array($this, "onRedirect"));
}
public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $index => $listener)
{
if ($events->detach($listener))
{
unset($this->listeners[$index]);
}
}
}
public function onRedirect(EventInterface $e)
{
...
}
原因很简单。我试图在触发事件时向数据库中添加一些内容,但我无法在侦听器上获取 serviceLocator。我不知道为什么。
那么...是否可以在没有 serviceLocator 的情况下获取配置文件?
【问题讨论】:
-
我宁愿试着找出你无法在你的听众中得到
ServiceLocator的原因。这应该是可能的。有了你的问题,你并没有解决实际的问题。您能否详细说明为什么您无法在侦听器中获取您的ServiceLocator?
标签: php events zend-framework2 service-locator