이상한 문제가 있습니다. 누군가가 나를 도울 수 있기를 바랍니다.Zend Rest Api : POST 메서드의 putAction
저는 Zend를 처음 사용하고 있으며, RESTfull API를 작성하고 있습니다.
curl 명령을 POST 메서드로 실행하면 putAction() 함수가 호출됩니다.
예를 들어, 나는 컬 명령을 실행하고 :
[...]
public function postAction() {
echo 'Method = ' . $_SERVER['REQUEST_METHOD'];
if (!$id = $this->_getParam('id', false)) {
$this->sendResponse("Bad request. Id is missing", 400);
}
$this->sendResponse("From postAction() creating the requested article", 201);
}
public function putAction() {
echo 'Method = ' . $_SERVER['REQUEST_METHOD'];
$this->sendResponse("From putAction() updating the requested article");
}
[...]
어떤 아이디어 : 여기
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> POST /ws/user/post HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 22 Oct 2012 13:37:56 GMT
< Server: Apache/2.2.14 (Ubuntu)
< X-Powered-By: PHP/5.3.2-1ubuntu4.18
< Vary: Accept-Encoding
< Content-Length: 53
< Content-Type: text/html
<
* Connection #0 to host localhost left intact
"From putAction() updating the requested article"
Method = POST
* Closing connection #0
코드입니다 :
여기curl -X POST http://localhost/ws/user/post -v
는 반응이다?
편집 : 나는 내 부트 스트랩에이 코드를 넣을 것을 깨달았다
: 나는 그것을 언급 할 때, 작동
public function _initRestRoute() {
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$restRoute = new Zend_Rest_Route($front, array(), array(
'ws',
));
$router->addRoute('rest', $restRoute);
}
.
설명이 있으십니까? 감사!
컨트롤러는 무엇을 확장합니까? 기본 Zend 컨트롤러 또는 나머지 Route 하나? – ficuscr
Zend_Rest_Controller에서 확장됩니다. – Kornikopic