Zend Framework 2:PostService::savePost() 必须兼容 Blog\Service\PostServiceInterface::savePost(Blog\Model\PostInterface $blog) 问题
Zend Framework 2: PostService::savePost() must be compatible with Blog\Service\PostServiceInterface::savePost(Blog\Model\PostInterface $blog) issue
我在使用 link Making use of Forms and Fieldsets 在 Zend Framework 2 中添加博客 post 时遇到了这个问题。我仔细检查过我是否遗漏了什么。任何人都可以帮助我哪里出错或遗漏任何东西吗?因为我是 Zend Framework 的新手,所以很难跟踪这个问题。
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;
use Blog\Model\PostInterface;//this clause is missing in the tutorial link
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);
}
}
如果我没有看错的话,在您下面的示例中,PostServiceClass
中似乎缺少一个 use Blog\Model\PostInterface;
子句。
这导致 savePost
方法中使用的 PostInterface
成为 Blog\Service\PostInterface
而不是 Blog\Model\PostInterface
,因此 savePost
的实现方法与其在接口中的声明不兼容
我在使用 link Making use of Forms and Fieldsets 在 Zend Framework 2 中添加博客 post 时遇到了这个问题。我仔细检查过我是否遗漏了什么。任何人都可以帮助我哪里出错或遗漏任何东西吗?因为我是 Zend Framework 的新手,所以很难跟踪这个问题。
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;
use Blog\Model\PostInterface;//this clause is missing in the tutorial link
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);
}
}
如果我没有看错的话,在您下面的示例中,PostServiceClass
中似乎缺少一个 use Blog\Model\PostInterface;
子句。
这导致 savePost
方法中使用的 PostInterface
成为 Blog\Service\PostInterface
而不是 Blog\Model\PostInterface
,因此 savePost
的实现方法与其在接口中的声明不兼容