[英]RESTws using php + symfony + Zend with response in json format
我是symfony和php zend的新手
我正在使用symfony 1.x和Zend 1.11.6和PHP构建RESTws
这是我的代码:
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);
}
呼叫WS:
http://localost:9000/test_debug.php/api/showList.json?method=getDeltaList&to=1341705600&from=1341100800
输出:
<?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>
我的要求是只输出不带xml标签的json响应,我在Google上搜索了很多,但找不到解决方案。 您能否建议我如何仅使用json输出来响应Ws?
为什么使用Zend_Rest_Server
,我认为您可以仅使用symfony而不使用Zend来进行REST Web服务。
这里的例子:
关于你的问题。 我认为xml
返回Zend_Rest_Server
。 您可以检查问题, 使Zend_Rest_Server使用ZF返回JSON而不是XML ,然后尝试使用答案。 但是在评论中,我读到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
。 所以,祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.