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

私は私が(私のzend_versionを変更する必要がどのような https://framework.zend.com/manual/2.4/en/in-depth-guide/services-and-servicemanager.html

ですべてをやっています)。あなたのListControllerFactoryクラスがFactoryInterfaceを実装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

です。したがって、このインタフェースのすべての抽象関数をクラスに定義する必要があります。ここでは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.jsondev-masterを使用しないでください。私は、ZF2コンポーネントとZF2チュートリアルのみを使用することをお勧めします.ZF3を学びたい場合は、ZF3コンポーネントとZF3チュートリアルのみを使用することをお勧めします。

+0

タンク・ユー。私は最初からZF 2.4とその作業を開始しています。 – kgendig