2011-08-02 97 views
0

嗯,這是我第一次去Zend,並且面臨着設置restful api的任務。我用了Zend其餘控制器,其代碼例如是這樣的: -使用Zend休息控制器與Zend休息客戶端

myzendrestcontroller-"localhost/alice/Theb2cController.php" 
<?php 

class Theb2cController extends Zend_Rest_Controller 
{ 

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

    public function indexAction() { 
     $this->getResponse() 
      ->appendBody($xml); 
    } 

    public function getAction() { 
     if ($this->getRequest()->getParam ("name") != NULL) { 
     $return =" wow"; 
     } else { 
     $return= 'no parameters!'; 
     } 

     echo $return 
    } 

    public function postAction() { 
     $salutation=$this->getRequest()->getParam("salutation"); 
    } 

    public function putAction() { 
    } 

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

客戶看起來是這樣的: -

myzendclient-"localhost/alice1/theb2cclient.php" 
require_once("Zend/Rest/Client.php"); 
$url="localhost/alice/Theb2cController.php" 
$client1=new Zend_Rest_Client($url); 
$client1->name('alice'); 
$response=$client1->get(); 
echo $response; 

但我沒有得到任何迴應,這只是一個空白屏幕。有人可以請幫忙

+0

您是否將Zend的整個MVC框架或Zend_Rest類用作項目中的獨立對象? –

+0

@Adrian我在運行restful web服務項目時只使用了zend rest classes – Rasmus

回答

1

首先,如果你只有一個空白屏幕,即沒有什麼,那麼你應該看看你的錯誤配置。確保所有錯誤都使用display_errorserror_reporting以PHP顯示。

二,各地都有問題。當你使用Zend_Rest_Controller作爲一個獨立的對象而不是整個Zend MVC框架時,那麼你很可能會遺漏路由器,並且你的控制器中的所有引用都無法實現。事實上,當你打電話給你的其中一個動作時,你應該會看到錯誤,但你並沒有看到那麼遠。

Zend_Rest_Controller需要路由信息和視圖來呈現文檔,但是當您直接調用Theb2cController.php文件時,這一切都顯然缺失;包括錯誤報告!找到其他方式向您的客戶端呈現有效的URL,而無需控制器信息。

所以,以下是不會工作,因爲您的Theb2cController.php實際上沒有做和返回任何東西。

$url="localhost/alice/Theb2cController.php" 
$client1=new Zend_Rest_Client($url); 
+0

,我得到的錯誤選擇沒有包含任何可以在服務器上運行的資源。請幫我解決這個問題。也請幫助我一步一步地指導運行一個簡單的Web服務項目 – Sadanand