Child pages
  • Chapter 5 - Modification - Update client

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: xml en putXml

...

Retrieving the XML file and display the form:

Code Block

// Define the resource
$opt = array('resource' => 'customers');

// Define the resource id to modify
$opt['id'] = $_GET ['id'];

// Call the web service, recuperate the XML file
$xml = $webService->get( $opt );

// Retrieve resource elements in a variable (table)
$resources = $xml->children()->children();

// client form

...

Thus we will get it this way:

Code Block

$_GET['id'];

We could have done this differently, such as by passing this ID in a POST request, but you will see that this method will simplify the processing that follows.

...

Help for creating a form:

Code Block

foreach ($resources as $key => $resource) {
	echo '<tr><th>' . $key . '</th><td>';
	echo '<input type="text" name="' . $key . '" value="' . $resource . '"/>';
	echo '</td></tr>';
}

...

Path of the keys in the XML file and update values:

Code Block

foreach ($resources as $nodeKey => $node) {
	$resources->$nodeKey = $_POST[$nodeKey];
}

...

Example of an update:

Code Block

// Resource definition
$opt = array('resource' => 'customers'); 

//XML file definition
$opt['xmlputXml'] = $xml->asXML();

// Definition of ID to modify 
$opt['id'] = $_GET[ 'id' ]; 

// Calling asXML () returns a string corresponding to the file
$xml = $webService->edit($opt);

...