PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 13, 2022

[FIXED] How to use CakePHP exclusively for the API?

 February 13, 2022     api, cakephp, cakephp-3.0, curl, php     No comments   

Issue

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.


Solution

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



Answered By - SamHecquet
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing