首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ZF3介绍服务和ServiceManager

ZF3介绍服务和ServiceManager
EN

Stack Overflow用户
提问于 2016-09-27 07:10:59
回答 1查看 614关注 0票数 1

我搞错了:

代码语言:javascript
复制
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

代码语言:javascript
复制
<?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);
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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教程。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39718265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档