dongshi6844 2017-03-18 21:17
浏览 134
已采纳

如何将CakePHP专门用于API?

I have a API made with CakePHP and I don't want to use the views to display something on the website, for example I'd like to be able to use api.mydomain.com/users in CURL, but if I try to go to the URL in my browser I want it to redirect to api.mydomain.com which will be my API documentation. I want this to be for every controller.

I don't know if my question is clear, but I only want my site to serve JSON responses and nothing else. If there's a better solution to my question, I'd like to hear it too.

Thanks for helping.

  • 写回答

1条回答 默认 最新

  • douhoujun9304 2017-03-20 14:49
    关注

    You need to use JSON and XML views. In this way, you'll render a JSON response.

    I don't think you should redirect to the api.mydomain.com, it's pretty common to access API through a browser, but if you really want to do it you have to take a look at $_SERVER['HTTP_USER_AGENT'] variable

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

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失