Using the SMODL PHP Client
This document shows how to automatically generate and use a PHP Client with the Smodl Development Suite. It is an add-on to the SMODL tutorial, with which the reader is assumed to be familiar. It is also assumed that the reader knows how to use PHP in general.
Enable automatic PHP code-generation for the client
From the Package Explorer view, create a folder for your PHP code called "src/php". Open the property page for the SMODL file and choose the "PHP Module" tab. Select the checkbox "Generate PHP client" and fill in values as shown in the picture below.

When applying these settings, some files will appear in the "src/php" folder. The file called "CRUD.php" holds the PHP implementation of the Employee DTO and service-object called "CRUD". Additionally, two other files containing run-time support for SMODL are copied from the php-plugin jarfile into the same folder. Please do not change any of these files as they may be overwritten without notice. If you really need to make changes to the PHP code, copy all the files from "src/php" into another folder and change the copies.
Write the PHP client implementation
Create a new file in "src/php" called "Client.php". Paste the following code into the file
<?php
require_once("CRUD.php");
$emp = array(
"id"=>"100",
"name"=>"John Doe",
"title"=>"Unknown",
"salary"=>0
);
$empObj = new Employee($emp);
$crudService = new CRUD();
$crudService->host = "localhost";
$crudService->port = 9080;
$crudService->baseURL = "/WS/JSON";
print("Creating new employee 100...");
$result = $crudService->create($empObj);
if ($result) print "ok\n";
else print "failed\n";
print("Retrieving employee 100...\n");
$result = $crudService->retrieve("100");
if ($result == null) print "no such record!\n";
else print_r($result);
print("Updating employee 100...");
$empObj->salary=1000000;
$result = $crudService->update("100", $empObj);
if ($result) print "ok\n";
else print "failed\n";
print("Retrieving employee 100...\n");
$result = $crudService->retrieve("100");
if ($result == null) print " no such record\n";
else print_r($result);
print("Retrieving employee 200...\n");
$result = $crudService->retrieve("200");
if ($result == null) print " no such record\n";
else print_r($result);
print("Deleting employee 100...\n");
$result = $crudService->delete("100");
if ($result == null) print " no such record\n";
else print_r($result);
print("Deleting employee 100 again...\n");
$result = $crudService->delete("100");
if ($result == null) print " no such record\n";
else print_r($result);
?>
Assuming that the server runs like described in the SMODL tutorial, this simple PHP client can be used to access the service. Note that the service is accessed over the JSON-RPC protocol.