dongmo6937 2013-07-30 14:52
浏览 61
已采纳

如何使用相同的CakePhp设置开发网站和API

I am going to work on a website having features like pinterest.com, simultaneously I will have to develop API for android and iPhone apps, I am planning to develop this website in CakePhp, my question is how can I develop website and API using same models and controller, i.e. only the view layer will change in case of website it will be html and in case of API it will be json. Is is possible to do this efficiently, and what coding pattern should I follow, please give me any open source examples of code.

this link gives me some information but detailed instructions will be helpful :)

  • 写回答

1条回答 默认 最新

  • duanbamo0127 2013-07-30 15:21
    关注

    Considering every controller method can pass data to the view. You would then just have to map the resources. Here is a article on how mapping resources can work: RESTFUL cakephp. I would also recommend just reading through the documentation REST. This process is rather simple. For example the url todo/123 would go to a view that has html. The url todo/123.json would redirect to a different /json/ folder in cakephp structure and you would json_encode($data).

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

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探