开发者

Using Zend rest controller with a zend rest client

Well this is my first trip to Zend and am faced with a task of setting a restful api. I used the zend rest controller whose code for example look like this:-

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");
   }
}
?>  

The client looks like this:-

myzendclient-"localhost/alice1/theb2cclient.php"
require_once("Zend/Rest/Client.php");
$url="localhost/alice/Theb2cController.php"
$client1=new Ze开发者_开发知识库nd_Rest_Client($url);
$client1->name('alice');
$response=$client1->get();
echo $response;

But I dont get any response, it is just a blank screen. Can someone please help


First of all, if you only get a blank screen, i.e. nothing at all then you should look at your error configuration. Make sure that all errors are shown in PHP with display_errors and error_reporting.

Second, there are problems all over. When you use the Zend_Rest_Controller as an independent object and not the whole Zend MVC Framework then you are most likely missing the router and all the $this references in your controller go nowhere really. Actually you should see errors when you call one of the actions but you are not as far as I see.

The Zend_Rest_Controller needs routing information and a view to render a document but when you call the Theb2cController.php file directly this all is clearly missing; including the error reporting! Find other ways to present a valid URL to your client without the controller information.

So, the following is not going to work because your Theb2cController.php is actually not doing and returning anything.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜