简而言之:我需要从外部类访问服务管理器(定位器)。
细节:
我的 ZF2 项目中有下一个结构:
Api.php 是我在 SOAP 服务器中使用的类,它是在 Controller 中创建的:
class IncomingInterfaceController extends AbstractActionController
{
...
public function indexAction()
{
if (isset($_GET['wsdl']))
$this->handleWSDL();
else
$this->handleSOAP();
return $this->getResponse();
}
private function handleWSDL()
{
$autodiscover = new AutoDiscover();
$autodiscover->setClass('\Application\Api\Api')->setUri($this->getURI());
$autodiscover->handle();
}
在这个 Api.php 类中,我需要访问服务。
我的 Api.php 类中需要这样的东西:
public function OnNewDeal($uid)
{
$error_log=$this->getServiceLocator()->get('error_log'); // this doesn't work!
$error_log->write_error('error_text');
}