2016-09-27 4 views
1

내가지고있어 오류 :ZF 3 개 소개 서비스 및 ServiceManager에

Fatal error: Class Blog\Factory\ListControllerFactory contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Zend\ServiceManager\Factory\FactoryInterface::__invoke) in /d0/home/kgendig/www/Zend/module/Blog/src/Blog/Factory/ListControllerFactory.php on line 28 

내가 변경해야 할 무엇 https://framework.zend.com/manual/2.4/en/in-depth-guide/services-and-servicemanager.html

, 내 zend_version() 모든 일을 해요; 2.6.0

<?php 
// Filename: /module/Blog/src/Blog/Factory/ListControllerFactory.php 
namespace Blog\Factory; 

use Blog\Controller\ListController; 
use Zend\ServiceManager\FactoryInterface; 
use Zend\ServiceManager\ServiceLocatorInterface; 

class ListControllerFactory implements FactoryInterface 
{ 
    /** 
    * Create service 
    * 
    * @param ServiceLocatorInterface $serviceLocator 
    * 
    * @return mixed 
    */ 
    public function createService(ServiceLocatorInterface $serviceLocator) 
    { 
     $realServiceLocator = $serviceLocator->getServiceLocator(); 
     $postService  = $realServiceLocator->get('Blog\Service\PostServiceInterface'); 

     return new ListController($postService); 
    } 
} 
+0

'ListControllerFactory.php'를 주면 코드를주지 않으면 아무도 잘못된 것을 말할 수 없습니다. 그렇다면 ZF3에 대해 이야기하고 있지만 ZF2.4 설명서에 대한 링크를 제공하고 2.6 버전이 있어야합니다. ZF2 또는 ZF3와 함께 작동하지만 함께 작동하도록 설계되지 않은 부품은 사용하지 마십시오 ... –

+0

ok 내 첫 번째 메모 – kgendig

답변

1

당신의 ListControllerFactory 클래스는 FactoryInterface를 구현합니다. 따라서이 인터페이스의 모든 추상 함수를 클래스에 정의해야합니다. 여기에서 FactoryInterface에는 __invoke() 메소드가 필요하므로 (호출 방법을 확인하십시오), ListControllerFactory에 정의해야합니다.

ZF2/3 구성 요소가 혼합되어있는 것처럼 보입니다. ZF3 FactoryInterface 코드 (see here)에서는 V3에 V2로 업그레이드하기위한 지침을 가지고

If upgrading from v2, take the following steps:

  • rename the method createService() to __invoke() , and:
  • rename the $serviceLocator argument to $container , and change the typehint to Interop\Container\ContainerInterface
  • add the $requestedName as a second argument
  • add the optional array $options = null argument as a final argument
  • create a createService() method as defined in this interface, and have it proxy to __invoke() .

이 문제를 해결하는 방법에 대해 설명합니다,하지만 어쩌면 당신의 코드에서 몇 가지 유사한 문제가있다. ZF2.4 및 ZF3 구성 요소를 혼합하지 마십시오. composer.jsondev-master을 사용하지 마십시오. ZF2 구성 요소 및 ZF2 자습서 만 사용하거나 ZF3를 배우려면 ZF3 구성 요소 및 ZF3 자습서 만 사용하는 것이 좋습니다.

+0

탱크에 붙여 넣습니다. 저는 처음부터 ZF 2.4와 그 작업을 시작합니다. – kgendig