Question

I am new to symfony and php zend

I am building RESTws using symfony 1.x and Zend 1.11.6 and PHP

here is my code :

routine.yml --

api_highConfidenceHash:
  url:    /api/showList.:sf_format
  class:  sfPropelRoute
  param:  { module: api, action: showList}
  options: { model: showListWS, type: list, method: getDeltaList}
  requirements:
    sf_format: (?:json)   

action.class.php --

 public function executeshowList(sfWebRequest $request) {

        require_once 'Zend/Rest/Server.php';
        $server = new Zend_Rest_Server();
        $server->setClass('showList');
        $server->handle();
    }

showList.class.php --

class showList{
      public function getDeltaList($to,$from){
        return json_encode(array('to'=>$to,'from'=>$from);
       }

Calling WS:

http://localost:9000/test_debug.php/api/showList.json?method=getDeltaList&to=1341705600&from=1341100800

output:

<?xml version="1.0" encoding="UTF-8"?>
<showList generator="zend" version="1.0"><showList><response>{"from":"1341100800","to":"1341705600"}</response><status>success</status></showList></showList>

My requirement is to only the json response output without xml tags , i googled a lot but not able to find solution . Could you please suggest me how can i reponse Ws with only json output.

Was it helpful?

Solution

Why you use Zend_Rest_Server, I think you can make REST webservice without Zend using only symfony.

Here example:

REST webservice with symfony

sfRestWebServicePlugin

About your question. I think that xml return Zend_Rest_Server. You can check question Make Zend_Rest_Server return JSON instead of XML using ZF, and try use answer. But in comment I read that Zend_Rest_Server is only working with XML. You can't decide the ouput format. So, good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top