I have made a full application in JQM using cakePHP as the server side language. Application at this stage is only available via the browser.
I have used standard SQL in PHP to pull all data and I am not using JSON at all. My question is do I have to pretty much ditch cakePHP to get my application working on iPHONE and adopt a more JSON approach?
I am quite new to JSON and have issues in regards to how i’ll handle access control and controlling what data is visible to certain users.
My thoughts so far would be to build a template for Phonegap so the app works offline and offers relevent error messages and my other app could be loaded into it once the user choose to login?
Any ideas or nudge in the right direction would be tops.
PHP can use json via the built-in functions json_encode and json_decode. So you can continue using CakePHP as the backend if you want, the client should neither know nor care.
For PHP JSON documentation, see: http://us.php.net/manual/en/function.json-encode.php
The use of JSON is a choice of what format you send data in between the client and server. JSON happens to be convenient on the client side which is written in Javascript. You don’t need to use JSON to make an iPhone-friendly web site / web app.
My general approach is to have a
toJSONfunction on my PHP data objects. I have a function that I use to send JSON to the client, and it first looks for thetoJSONmethod before sending the object. If it finds that, it calls it and sends the result of that. This gives the object a chance to present a minimal set of data members as opposed to sending everything. This is the same basic approach used in Ruby on Rails too.Here’s an example. Perhaps CakePHP has their own equivalent of this: