2011-01-06 40 views
1

m開發rest by zf。 這是我的用戶控制器。rest api action

<?php 
class UserController extends Zend_Rest_Controller 
{ 

    public function init() 
    { 
     $this->_helper->viewRenderer->setNoRender(true); 
    } 

    public function indexAction() 
    { 
     $this->getResponse() 
      ->appendBody("From indexAction() returning all articles"); 
    } 

    public function getAction() 
    { 
     $this->getResponse() 
      ->appendBody("From getAction() returning the requested article"); 

    } 

    public function postAction() 
    { 
     $this->getResponse() 
      ->appendBody("From postAction() creating the requested article"); 

    } 

    public function putAction() 
    { 
     $this->getResponse() 
      ->appendBody("From putAction() updating the requested article"); 

    } 

    public function deleteAction() 
    { 
     $this->getResponse() 
      ->appendBody("From deleteAction() deleting the requested article"); 

    } 


} 
?> 

通過運行此網址http://quickstart.local/user/ m到處

From indexAction() returning all articles 

,並通過運行這個網址http://quickstart.local/user/1米越來越

From getAction() returning the requested article 

如何測試POST,PUT,刪除操作。

感謝

回答

2

嘗試發送POST,PUT和通過捲曲DELETE請求到控制器的網址.. Zend_Rest_Controller會自動路線該請求採取適當行動。

謝謝!

-1

HII

遵循這個模式

http://quickstart.local/controller/action_name 

Sanil

+0

如果我這樣做http://quickstart.local/user/delete/它也稱爲getaction。 – XMen 2011-01-06 10:29:08

+0

嘗試重命名你的行動到一些其他的行動,然後再試一次 – lampdev 2011-01-06 10:31:35