0

Zend \ Di에 대한 도움말이 필요합니다.Zend Di 구성 방법

Zend \ ServiceManager를 사용하여 응용 프로그램에 공장을 작성하는 작업에 지치기 때문에 Zend \ Di의 MVC 환경에서 구성 작업이 어떻게 작동하는지 알고 싶습니다.

내가 상단 키 di에서 module.config.php의 일부 구성, this post of @Ocramius 참조

:

<?php 

return array(
    'di' => array(
     'allowed_controllers' => array(
      // this config is required, otherwise the MVC won't even attempt to ask Di for the controller! 
      'Application\Controller\GreetingController', 
     ), 

     'instance' => array(
      'preference' => array(
       // these allow injecting correct EventManager and ServiceManager 
       // (taken from the main ServiceManager) into the controller, 
       // because Di doesn't know how to retrieve abstract types. These 
       // dependencies are inherited from Zend\Mvc\Controller\AbstractController 
       'Zend\EventManager\EventManagerInterface' => 'EventManager', 
       'Zend\ServiceManager\ServiceLocatorInterface' => 'ServiceManager', 
      ), 
     ), 
    ), 
    // remaining config 
); 

누구나이 구성 또는 여기에 더 자세한 예제의 문서에 URL을 게시 할 수 있습니까?

답변

1

서로 다른 컨트롤러를 많이 가지고 다음 구성하거나 주석을 가진 사람이 링크에서 선택을해야 선택할 수있는 많은 서비스가있는 경우 : https://github.com/ralphschindler/Zend_DI-Examples

난 당신이 어떤 라이브러리를 봐야한다 생각을 Aura.Di 또는 Pimple입니다. 강력한 DI 컨테이너를 제공합니다.

삽입 할 서비스가 최소한이라면 초기화 프로그램을 사용하십시오. 이것을 확인하십시오 : http://akrabat.com/zend-framework-2/zendservicemanager-configuration-keys/

+0

같은 것은 아니며 많은 초기화 프로그램을 가질 수 없습니다. 각각은 서비스 관리자에게 요청할 때마다 실행됩니다. –

+1

컨트롤러가 많고 선택할 수있는 서비스가 많은 경우 Configuration 또는 Annotation을 사용하는 컨트롤러가 다음 링크에서 선택해야합니다. https : //github.com/ralphschindler/Zend_DI-Examples – Pradeep

+0

감사합니다. 나는 이것을 module.config.php의 "di"w 키에 사용하려고 시도 할 것이다. 슬픈 일로 잘 문서화 된 방법이 아닙니다. 응답 또는 응답을 다시 변경하여 올바른 것으로 선택하십시오. –