在使用链接使用表单和字段集在Zend 2中添加博客文章时,我面临着这个问题。我已经仔细检查过我是否漏掉了什么。有人能帮我找错地方或遗漏什么吗?因为我是新的,所以很难追踪这个问题。
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修复此错误所需的文件如下所示:
<?php
// Filename: /module/Blog/src/Blog/Service/PostService.php
namespace Blog\Service;在Blog\Model\PostInterface;//this中缺少use 教程链接子句
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);
}
}发布于 2016-07-19 09:50:18
如果正确的话,在下面的示例中,PostServiceClass中缺少一个use Blog\Model\PostInterface;子句。
这导致在savePost方法中使用的savePost是Blog\Service\PostInterface而不是Blog\Model\PostInterface,因此savePost方法的实现与接口中的声明不兼容。
https://stackoverflow.com/questions/38454673
复制相似问题