简体   繁体   English

使用php + symfony + Zend和json格式的响应的RESTws

[英]RESTws using php + symfony + Zend with response in json format

I am new to symfony and php zend 我是symfony和php zend的新手

I am building RESTws using symfony 1.x and Zend 1.11.6 and PHP 我正在使用symfony 1.x和Zend 1.11.6和PHP构建RESTws

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: 呼叫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 . 我的要求是只输出不带xml标签的json响应,我在Google上搜索了很多,但找不到解决方案。 Could you please suggest me how can i reponse Ws with only json output. 您能否建议我如何仅使用json输出来响应Ws?

Why you use Zend_Rest_Server , I think you can make REST webservice without Zend using only symfony. 为什么使用Zend_Rest_Server ,我认为您可以仅使用symfony而不使用Zend来进行REST Web服务。

Here example: 这里的例子:

REST webservice with symfony 带有symfony的REST Web服务

sfRestWebServicePlugin sfRestWebServicePlugin

About your question. 关于你的问题。 I think that xml return Zend_Rest_Server . 我认为xml返回Zend_Rest_Server You can check question Make Zend_Rest_Server return JSON instead of XML using ZF , and try use answer. 您可以检查问题, 使Zend_Rest_Server使用ZF返回JSON而不是XML ,然后尝试使用答案。 But in comment I read that Zend_Rest_Server is only working with XML. You can't decide the ouput format 但是在评论中,我读到Zend_Rest_Server is only working with XML. You can't decide the ouput format Zend_Rest_Server is only working with XML. You can't decide the ouput format . Zend_Rest_Server is only working with XML. You can't decide the ouput format So, good luck! 所以,祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM