我在2.0.4。
我的档案:
https://gist.github.com/4191490
根据http://framework.zend.com/manual/2.0/en/modules/zend.service-manager.quick-start.html
的文件如果一个类实现了ServiceManagerAwareInterface,那么它的对象将使用服务管理器进行初始化。我做了同样的事情(参见我的源代码中的BaseEntity.php)。但是,服务管理器从未初始化,因此无法从子类Snippet中获取。
问题:如何检索全局或模块的ServireManager实例,以便我可以访问其他服务? (大多数都是单身人士)
答案 0 :(得分:1)
ServiceManagerAwareInterface
已被弃用,不会被注销
使用ServiceLocatorAwareInterface
代替
答案 1 :(得分:1)
要使ServiceManagerAwareInterface
按照建议工作,实例需要来自ServiceManager
。这是因为如果找到该接口,就会在注入ServiceManager的ServiceManager
附加一个Initalizer(您可以在 - Zend\Mvc\Service\ServiceManagerConfig
中看到这一点。)
您可以将您的类添加到SevriceManager配置中,然后通过$sm
实例提取它们,甚至修改您的getTableGateway以添加以下内容:
if ($prototype instanceof ServiceManagerAwareInterface)
{
$prototype->setServiceManager($sm);
}