2012-12-02 4 views
0

저는 2.0.4를 사용 중입니다.이 Zend Framework 2의 ServiceManager에 액세스 할 수 없습니다.

내 파일 : 클래스가 ServiceManagerAwareInterface를 구현하는 경우

https://gist.github.com/4191490

http://framework.zend.com/manual/2.0/en/modules/zend.service-manager.quick-start.html

의 문서에 따르면, 다음의 객체는 서비스 관리자로 초기화됩니다. 나는 같은 것을했다. (내 소스 코드에서 BaseEntity.php를 보라). 그러나 서비스 관리자는 초기화되지 않았으므로 하위 클래스 스 니펫에서 사용할 수 없습니다.

질문 : 글로벌 또는 모듈의 ServireManager 인스턴스를 검색하여 다른 서비스에 액세스 할 수있는 방법은 무엇입니까?

답변

1


사용 ServiceLocatorAwareInterface을 aoutoinjected되지 않는다 (그들 대부분은 싱글입니다). 이는 해당 인터페이스가 발견되면 ServiceManager를 주입하는 ServiceManager에 첨부 된 Initalizer가 있기 때문입니다 (이 내용은 Zend\Mvc\Service\ServiceManagerConfig에서 볼 수 있습니다). ServiceManager에 통과 한,

if ($prototype instanceof ServiceManagerAwareInterface) 
{ 
    $prototype->setServiceManager($sm); 
} 
1

ServiceManagerAwareInterface는 사용되지 않으며 인스턴스가 ServiceManager 나올 필요가 제안 작업을 ServiceManagerAwareInterface 대신

+0

실제로 ServiceManagerAwareInterface 사용의 하나입니다

다음 추가 할 $sm 인스턴스를 통해 그들을 잡아 당기거나 심지어 getTableGateway을 수정 한 후 SevriceManager 구성에 클래스를 추가 할 수 ServiceLocator가 아닌 Module.php의 팩토리 메소드에 전달합니다. 문제는 ServiceManagerAwareInterface가 자동으로 초기화되지 않아서 DrBeza가 제안한대로 모든 인스턴스를 수동으로 초기화하는 것이 었습니다. – thoaionline

+0

ACTUALLY ServiceManagerAwareInterface는 더 이상 사용되지 않습니다. ServiceManager가 구체적 ServiceLocator이기 때문에 ServiceLocatorAwareInterface를 대신 사용하십시오. – Xerkus

관련 문제