Difference between revisions of "PHP"

From MyMobileWorkers API
Jump to: navigation, search
(Created page with "<source lang="php"> <?php v = "string"; // sample initialization ?> html text <?php echo v; // end of php code ?> </source>")
 
Line 1: Line 1:
 +
Since PHP as built in functions to encode/decode JSON it provides a quick and easy method to test the API.
 +
 +
Using OOP is the most sensible approach so create a class called Job.
 +
 +
=== Job.php ===
 
<source lang="php">
 
<source lang="php">
−
<?php
+
 
−
    v = "string";   // sample initialization
+
class Job {
−
?>
+
 
−
html text
+
public $job_number;
−
<?php
+
public $address_1;
−
    echo v;         // end of php code
+
public $address_2;
−
?>
+
public $contact_name;
 +
public $contact_number_1;
 +
public $contact_number_2;
 +
public $mobile_user = array();//username not id
 +
public $postcode;
 +
public $type = 'repair';//job type in mmw
 +
public $timeslot;
 +
public $special_instructions;
 +
public $repair_description;
 +
 
 +
function __construct(){
 +
 
 +
//Here you could pass an ID and populate the job from a mysql record etc..
 +
 
 +
$job_number = "TEST_JOB01";
 +
$address_1 = "ADDRESS LINE 1";
 +
-------- populate further records
 +
$repair_description = "Faulty whatsit";
 +
 
 +
 
 +
}
 +
 
 +
function getJSON(){
 +
// we have a container array so the structure what the API expects
 +
// we send 1 job at a time but the api can handle an array of jobs. We send an array ($container) of 1 job basically.
 +
$jobs = array();
 +
$container = array();
 +
$container[] = $this;
 +
$jobs['jobs'] = $container;
 +
 +
return json_encode($jobs);
 +
 
 +
}
 +
 
 +
 
 +
}
 +
 
 
</source>
 
</source>

Revision as of 14:46, 14 May 2013

Since PHP as built in functions to encode/decode JSON it provides a quick and easy method to test the API.

Using OOP is the most sensible approach so create a class called Job.

Job.php

class Job {
 
	public $job_number;
	public $address_1;
	public $address_2;
	public $contact_name;
	public $contact_number_1;
	public $contact_number_2;
	public $mobile_user = array();//username not id
	public $postcode;
	public $type = 'repair';//job type in mmw
	public $timeslot;
	public $special_instructions;
	public $repair_description;
 
function __construct(){
 
//Here you could pass an ID and populate the job from a mysql record etc..
 
$job_number = "TEST_JOB01";
$address_1 = "ADDRESS LINE 1";
-------- populate further records
$repair_description = "Faulty whatsit";
 
 
}
 
function getJSON(){
	// we have a container array so the structure what the API expects
	// we send 1 job at a time but the api can handle an array of jobs. We send an array ($container) of 1 job basically.
		$jobs = array();
		$container = array();
		$container[] = $this;
		$jobs['jobs'] = $container;
 
		return json_encode($jobs);
 
	}
 
 
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox