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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘