我搞错了:
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);
}
}发布于 2016-09-27 09:42:26
您的ListControllerFactory类实现了FactoryInterface。因此,您必须在类中定义这个接口的所有抽象函数。在这里,您的FactoryInterface需要__invoke()方法(检查如何调用它),因此您必须在ListControllerFactory中定义它。
似乎你正在混合ZF2/3组件。在ZF3 FactoryInterface代码(请看这里)中,有关于从V2升级到V3的说明:
如果从v2升级,请执行以下步骤:
createService()重命名为__invoke(),并:$serviceLocator参数重命名为$container,并将类型提示更改为Interop\Container\ContainerInterface$requestedName作为第二个参数array $options = null参数作为最终参数createService()方法,并让它代理到__invoke()。这描述了如何解决问题,但在代码中可能有几个类似的问题。尽量不要混合ZF2.4和ZF3组件。不要在您的dev-master中使用composer.json。我建议您只使用ZF2组件和ZF2教程,或者,如果您想学习ZF3,则只使用ZF3组件和ZF3教程。
https://stackoverflow.com/questions/39718265
复制相似问题