guys, 在這一點上,我已經接近開始將頭髮拉出我的頭。我找不到達到此目的的方法。ZF2如何獲得服務經理對不是控制器,幫手或服務的自定義類的訪問
我有一個自定義類屬於我的WebServices模塊src文件夾下創建的自定義文件夾。我需要能夠從另一個模塊/控制器內部實例化這個類,但是當我這樣做並轉儲它包含null的服務成員時。 我怎麼能從我的ApiAuthentication類裏面訪問服務管理器。
任何幫助將不勝感激。由於
<?php
namespace WebServices\Services;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class ApiAuthenticationService extends \Zend\Soap\Client implements ServiceLocatorAwareInterface{
public $services;
function __construct($options = null){
parent::__construct('http://tinysoa.local/soap/security/api_authentication?wsdl',$options);
}
public function setServiceLocator(ServiceLocatorInterface $locator)
{
$this->services = $locator;
}
public function getServiceLocator()
{
return $this->services;
}
}
當我把這個從另一個模塊/控制器裏面轉儲一個空值:
class IndexController extends AbstractActionController
{
public function indexAction()
{
$a = new \WebServices\Services\ApiAuthenticationService();
var_dump($a->services);
這很好。但我想知道是否有其他解決方案,因爲有了這個對象實例化,當我通過服務定位器訪問它,但我需要傳遞參數給對象的構造函數。有沒有解決方案? – slash
是的,你可以傳遞參數。看看timdev的解決方案。 –