Using PHP to generate the app interface data is very simple, if you do not know PHP is not related, only need to read the basic PHP syntax, and then look at this example can be.
The app interface is generally JSON (and, of course, a few XML formats) that follow the restful specification:
{ code:200, msg: "This is the cue data", data:[here is the array data] }
To be able to see the effect first, here is the simplest and simplest demo code
The following is a basic complete demo code, with cache and database query. First look at the simple:
Two files: One encapsulates the method of generating JSON, and the other is the request interface file:
response.php
<?php class response{ /** * @param $code Status Code * @param string $message message * @param array $data data c10/>* return String * Output Communication data as JSON * /public static function json ($code, $message = ", $data =array ()) { if (!is_numeric ($code)) { return '; } $result = Array ( ' code ' = = $code, ' message ' = $message, ' data ' = $data ); echo Json_encode ($result); Exit; }}
test.php
<?phprequire_once ('./response.php '); $arr = Array ( ' id ' = = 1, ' name ' = ' Singwa '); Response::json (200, "Data return Success", $arr);
Two files, completed a simple Request interface demo, now test, I installed a local phpstudy, put these two files in the WWW root directory, browser input interface address
http://localhost/test.php