2016-09-27 24 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

好吧,我把它粘貼到我的第一個音符 – kgendig

回答

1

ListControllerFactory類實現FactoryInterface。所以你必須在你的類中定義這個接口的所有抽象函數。在這裏,您的FactoryInterface需要__invoke()方法(請查看您如何稱呼它),因此您必須在ListControllerFactory中對其進行定義。

看來你是混合ZF2/3組件。在ZF3 FactoryInterface代碼(see here),你必須說明從V2升級到V3:

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.json中使用dev-master。我建議你只使用ZF2組件和ZF2教程,或者,如果你想學習ZF3,只使用ZF3組件和ZF3教程。

+0

坦克你。我從開始安裝ZF 2.4及其作品開始。 – kgendig