Make Zend_Rest_Server return JSON instead of XML using ZF

落爺英雄遲暮 提交于 2019-12-22 18:45:19

问题


Can Zend_Rest_Server return Json ? If not, what are the alternatives ( other lib suggestions are ok also)


回答1:


Zend_Rest_Server outputs XML, eventhough not clearly specified in the documentation.

There are some alternatives:

You could leverage the whole MVC architecture given by Zend Framework, thanks to Zend_Rest_Route and Zend_Rest_Controller.
You will find a complete example here:
http://techchorus.net/create-restful-applications-using-zend-framework

Again, the example displays plain string, but using json_encode, or Zend_Json::encode should return json.

And finally, a complete (advanced) example that use the ContextSwitch feature:
http://www.chrisdanielson.com/2009/09/02/creating-a-php-rest-api-using-the-zend-framework/

(If you need more information on ContextSwitch Action Helper, please refer to the documentation.)

Unfortunately, my limited reputation prevent me from giving you more links, but Google is your friend using some magic words such as zend rest json or zend controller rest json ...



来源:https://stackoverflow.com/questions/5324311/make-zend-rest-server-return-json-instead-of-xml-using-zf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!