在兩天中的較好時間裏,我一直在絞盡腦汁。我正在使用Zend Apigility創建一個RESTful Web API應用程序。 Apigility使用ZF2構建應用程序。ZF2在自定義類中獲取自動加載的配置信息
我創建了一個我在我的API中使用的自定義類。
我想讀取一些自動加載的配置信息來建立到memcache服務器的連接。正被自動加載到服務管理的文件是:
memcache.config.local.php:我的REST服務都呼籲被稱爲checkAuth
return array(
'memcache' => array(
'server' => '10.70.2.86',
'port' => '11211',
),
);
我的自定義類:
checkAuth.php:
namespace equiAuth\V1\Rest\AuthTools;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class checkAuth implements ServiceLocatorAwareInterface{
protected $services;
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->services = $serviceLocator;
}
public function getServiceLocator()
{
return $this->services;
}
public function userAuths() {
//** Some Code
$config = $this->getServiceLocator()->get('config');
// **
}
}
我相信我注入服務經理成從我module.config.php類用下面的代碼:
'service_manager' => array(
'invokables' => array(
'checkAuth' => 'equiAuth\V1\Rest\AuthTools\checkAuth',
),
),
當我打的時候,我試圖讀取從服務定位器我得到的get方法的「配置」的代碼以下錯誤:
Fatal error: Call to a member function get() on a non-object
我知道我錯過了一些東西,但我不能爲我的生活找出什麼。