Reputation: 18651
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 :)
Upvotes: 2
Views: 442
Reputation: 1193
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).
Upvotes: 4