我有一個公共類,用於重用所有模塊的功能。我已經把它放在zf2工具類中的getServiceLocator
Application\Service\Utility.php
現在我可以在我的控制器對象作爲
$utilObj = new Utility();
然後調用我的功能$utilObj->myFn();
一切工作正常。
但我不能在那裏得到getServiceLocator()
函數(在myFn in Utility.php中)。有什麼辦法可以解決這個問題。 我需要服務定位器,因爲我必須得到配置數據,教條管理等。
我還沒有在module.php中配置getServiceConfig。
請閱讀我的兩個帖子:https://juriansluiman.nl/article/139/zf2-why-a-service-is-not-available-in-your-constructor和https://juriansluiman.nl/article/143 /收集思考關於dic-versus-sl-discussion來給你一些關於這個問題的見解 –