2016-11-25 47 views
0

我已經安裝數據庫適配器的配置,我可以使用鍵名稱,如獲得工廠數據庫服務:Apigility Zend的:獲取身份驗證服務使用密鑰名稱

$connectDb = $services->get('connectDb'); 

,然後我有鑰匙名設置認證適配器: 'connectoauth2' 它工作正常,並驗證我的休息api。

問題是,我想這個「connectoauth2」注入到我的UserEducation服務於getIdentity在於是我在工廠做了作爲

$connectDb = $services->get('connectDb'); 
$connectOAuth2 = $services->get('connectoauth2'); // --> service is not found 
$service = new \ConnectApp\Service\UserEducation($connectDb, $connectOAuth2); 
return new UserEducationResource($service); 

錯誤:無法" connectoauth2 "解析服務到廠;你確定你在配置期間提供了它嗎?

即使身份驗證工作正常,但仍然無法獲得服務,因爲我爲數據庫做了。

請幫忙!

謝謝!

+0

將需要看到您用來配置它的代碼.. – Andrew

回答

0

您確定$services是服務經理嗎?如果是另一種服務定位器實例(例如ControllerManagerViewHelperManager,而不是服務管理器),您必須首先從服務定位器獲得的服務經理:

$serviceManager = $services->getServiceLocator(); 

,然後從服務經理爲您服務:

$service = $serviceManager->get('connectoauth2'); 

檢查所有其他服務定位器的綜述還here

0

這只是Authentication AdapterAuthentication Service。因此,如果您需要從Authentication檢索identity,則應使用Authentication Service。在Zend Framework中,你可以調用Authentication Service這樣

$authentication = $serviceManager->get('authentication'); 

和檢索identity這個樣子。

$authentication->getIdentity()