Reputation: 2213
I am facing this issue while adding blog post in Zend Framework 2 using the link Making use of Forms and Fieldsets. I have double checked whether anything is missed by me. Can anybody help where i am going wrong or anything missing please. As i am new Zend Framework its little hard to track the issue.
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
The required file to fix this bug is given below:
<?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);
}
}
Upvotes: 1
Views: 139
Reputation: 9008
I if saw correctly, it looks like that in the example you are following, in the PostServiceClass
, a use Blog\Model\PostInterface;
clause is missing.
This is causing the PostInterface
used in the savePost
method to be a Blog\Service\PostInterface
and not a Blog\Model\PostInterface
and hence the implementation of the savePost
method is not complatible with its declaration in the interface
Upvotes: 1