duandai7601 2014-09-30 09:16
浏览 43
已采纳

symfony使用Web服务

I am working in symfony. I am retrivind data from a web service.

Currently I am using "Listener" to get data using web service. Is it wring way to do through listeners?

Is there any concept of Models in symfony to get data using web service? rather than calling web service from listener!

  • 写回答

1条回答 默认 最新

  • dsyua2828 2014-09-30 10:31
    关注

    Actually a listener isn't something that would fit your case. You need a regular service, because listeners are supposed to react to Symfony domain events.

    On creating services, you should read the official documentation (though if you've created an EventListener then most parts of the manual would be familiar to you).

    If you're wrapping a foreign API then you should definitely do some research on whether the API is already wrapped (packagist.org is a good start: here's a wrapper for Twitter's API for example). If it's not, then it's up to you to pick an HTTP client to communicate with the service, and wrap its API into a PHP class that you would then expose in your service.

    To understand how exactly you want to do this, try searching Packagist for Symfony bundles that wrap some APIs. Here's a Foursquare API bundle that uses an abstracted client library for example. Note that it depends on Guzzle HTTP client, and also take a look at the Guzzle Client class.

    Also, here's Google's official API client for PHP. You could grab some ideas from there, too.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测