我有一個小問題。我是Zend Framework 2中的新成員,我想用它創建一個REST服務。Zend Framework 2 REST API
我順着他的教程:http://www.slideshare.net/mikestowe/building-a-rest-api-with-zend-framework-2
的問題是,我得到一個錯誤信息,我沒有在任何地方找到它的谷歌。
致命錯誤:應用程序\控制器\ UserController中:: setEventManager的聲明()必須與Zend \ eventmanager進行\ EventManagerAwareInterface :: setEventManager(Zend的\ eventmanager進行\ EventManagerInterface $ eventmanager進行)的兼容C:\ WAMP \ WWW \ zf2rest \模塊\應用程序的\ src \應用\控制器\ UserController.php第15行
這是我的UserController中:
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class UserController extends AbstractRestfulController {
protected $collectionOptions = array('GET', 'POST');
protected $resourceOptions = array('GET', 'POST', 'DELETE');
protected function _getOptions() {
if($this->params->fromRoute('id', false)) {
// we have an id, return specific item
return $this->resourceOptions;
}
//no ID, return collection
return $this->collectionOptions;
}
public function options() {
$response = $this->getResponse();
//If in Options Array, Allow
$response->getHeaders()
->addHeaderLine('Allow', implode(',', $this->_getOptions()));
//return Response
return $response;
}
public function setEventManager(EventManagerInterface $events) {
//events propery defined in AbstractController
$this->events = $events;
//Register the listener and callback method with a priority if 10
$events->attach('dispatch', array($this, 'checkOptions'), 10);
}
public function checkOptions($e) {
if(in_array($e->getRequest()->getMethod(), $this->_getOptions())) {
//Method Allowed, Nothing to do
return;
}
//Method Not Allowed
$response = $this->getResponse();
$response->setStatusCode(405);
return $response;
}
}
有誰知道一個解決方案?
非常感謝!