首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ZendFramework2: PostService::savePost()必须与Blog\Service\PostServiceInterface::savePost(Blog\Model\PostInterface $blog兼容)

ZendFramework2: PostService::savePost()必须与Blog\Service\PostServiceInterface::savePost(Blog\Model\PostInterface $blog兼容)
EN

Stack Overflow用户
提问于 2016-07-19 09:34:33
回答 1查看 138关注 0票数 1

在使用链接使用表单和字段集在Zend 2中添加博客文章时,我面临着这个问题。我已经仔细检查过我是否漏掉了什么。有人能帮我找错地方或遗漏什么吗?因为我是新的,所以很难追踪这个问题。

代码语言:javascript
复制
Fatal error: Declaration of Blog\Service\PostService::savePost() must be compatible with Blog\Service\PostServiceInterface::savePost(Blog\Model\PostInterface $blog) in D:\xampp\htdocs\zf\module\Blog\src\Blog\Service\PostService.php on line 9

修复此错误所需的文件如下所示:

代码语言:javascript
复制
<?php

 // Filename: /module/Blog/src/Blog/Service/PostService.php

  namespace Blog\Service;

在Blog\Model\PostInterface;//this中缺少use 教程链接子句

代码语言:javascript
复制
  use Blog\Mapper\PostMapperInterface;

  class PostService implements PostServiceInterface {

   /**
   * @var \Blog\Mapper\PostMapperInterface
   */
   protected $postMapper;

   /**
    * @param PostMapperInterface $postMapper
    */
  public function __construct(PostMapperInterface $postMapper) {
    $this->postMapper = $postMapper;
    }

   /**
   * {@inheritDoc}
   */
   public function findAllPosts() {
      return $this->postMapper->findAll();
   }

   /**
   * {@inheritDoc}
   */
   public function findPost($id) {
      return $this->postMapper->find($id);
    }

    /**
    * {@inheritDoc}
    */
    public function savePost(PostInterface $post) {
      return $this->postMapper->save($post);
    }

 }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-19 09:50:18

如果正确的话,在下面的示例中,PostServiceClass中缺少一个use Blog\Model\PostInterface;子句。

这导致在savePost方法中使用的savePostBlog\Service\PostInterface而不是Blog\Model\PostInterface,因此savePost方法的实现与接口中的声明不兼容。

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

https://stackoverflow.com/questions/38454673

复制
相关文章

相似问题

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