你好,我试图运行This Blog Example所以我有本教程所说的每一个步骤,但现在我得到这个错误:创建工厂类后ZF2 - 1抽象方法,因此必须声明为抽象或实现
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 D:\xampp\htdocs\zend2test\module\Blog\src\Blog\Factory\ListControllerFactory.php on line 28
这里是我的工厂类:
// 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
{
private $serviceLocator;
/**
* 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);
}
}
如何解决这个问题?
感谢@yivi的答案,但加入后** __调用( )**现在它赋予这个---->'致命错误:声明Blog \ Factory \ ListControllerFactory :: __ invoke()必须与Zend \ ServiceManager \ Factory \ FactoryInterface :: __ invoke兼容(Interop \ Container \ ContainerInterface $ container ,$ requestedName,array $ options = NULL)' –
对不起。现在就试试。 – yivi
我已经试过,但是同样的错误 –