我是新來的Symfony和Zend的PHP的響應RESTws採用PHP +的symfony + Zend公司與JSON格式
我使用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,並通過直接渲染Json直接使用Symfony來感謝您的參考。 – Shashi