2012-10-22 3 views
3

이상한 문제가 있습니다. 누군가가 나를 도울 수 있기를 바랍니다.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); 
} 

.

설명이 있으십니까? 감사!

+0

컨트롤러는 무엇을 확장합니까? 기본 Zend 컨트롤러 또는 나머지 Route 하나? – ficuscr

+0

Zend_Rest_Controller에서 확장됩니다. – Kornikopic

답변

1

Zend_Rest_Route를 사용하는 중에 요청에 http://localhost/ws/user/post이 없어야합니다. 이 경로는/user/post를 매개 변수로 해석하고 action을 post에서 put으로 변경합니다. 대신 http://localhost/ws을 시도하십시오.

Zend/Rest/Route.php 라인 208을 참조하십시오.

+0

설명해 주셔서 감사합니다. 이제 어떻게 작동하는지 볼 수 있습니다. – Kornikopic