This section describes using the PHP Corda® Embedder, for those that use PHP to deliver Web content. Embedding a Corda image into a PHP can be broken down into the following steps:
The example code at the end of this section shows how to embed a Corda image in PHP.
Note: This documentation assumes that you are familiar with PHP.
Before including theCorda Embedder library into a PHP script, make sure that <product_root>\Server\dev_tools\embedder\php\CordaEmbedder.php is accessible to the PHP scripts. The easiest way of making them accessible is to copy it to the same folder as the scripts that use Corda Embedder. Alternatively, copy the CordaEmbedder.php file to a shared or includes directory that is accessible to PHP server.
To include the Corda Embedder library in a PHP script, use code similar to the following:
require("CordaEmbedder.php");
This instructs the PHP compiler to load the CordaEmbedder class.
To instantiate a Corda Embedder object, use code similar to the following:
$myImage = new CordaEmbedder();
All Corda Embedder code, including the require statement, should be delimited by <?php and ?>. For example:
<?php
$myImage->imageTemplate = "image_templates\examples\line.itxml";
$myImage->loadITXML("http://<server_address>/?graph1");
?>
Most of the example code in this Reference assumes that you are using the Java* Corda Embedder. Thus, you must convert the example code syntax for use with PHP. When doing this, consider the following:
PHP always uses pointer notation when calling methods or accessing attributes. This differs from the dot notation that is used in most of the examples in this documentation.
Variable names must always begin with a dollar sign.
For example, consider the following command in Java.
myImage.imageTemplate = "bar.itxml";
The equivalent code in PHP would be as follows:
$myImage->imageTemplate = "bar.itxml";
The following Corda Embedder methods are unavailable with PHP:
Corda Embedder needs to know two Corda Server™ addresses: the address that the Web client uses to access Corda Server (externalServerAddress), and the address that Corda Embedder uses to access Corda Server (internalCommPortAddress). For more information about determining these addresses, see Identifying Server Addresses.
For example, if the Corda Embedder communicates with Corda Server at 10.0.1.1:2002, and Web clients request images from http://<server_address>:2001, include the following in the code that generates the Corda image:
$myImage->externalServerAddress = "http://<server_address>:2001"
$myImage->internalCommPortAddress = "10.0.1.1:2002"
After specifying server address information, give Corda Embedder some information about the Corda image you want to embed.
There are numerous Corda Embedder commands to specify image information, which are consistent in all Web application environments (with the exception of several syntax differences, as previously explained in Syntax Notes). Thus, it is unnecessary to discuss each of these commands individually at this time.
The table below provides links to more information about Corda image features and components:
|
Topic |
Where To Go |
|
Annotations |
Data Annotations in the Corda Builder™ User Guide |
|
Content Delivery / Presentation Control |
|
|
Data |
|
|
Drilldown |
|
|
Graph or Map Customization |
|
|
Image Size & Format |
When you are ready to write the embedding HTML to the Web page, output the getEmbeddingHTML() method using an echo statement. For example:
echo $myImage->getEmbeddingHTML();
The code sample below demonstrates embedding a Corda image with PHP.
Note: To produce an example map instead of a graph, replace examples/bar.itxml with examples/map/australia_combo.itxml in the code designating the Image Template file.
Embedding a Corda Image with PHP
<html>
<head>
<title>My First Embedded Image</title>
</head>
<body>
<h1>This is your image</h1>
<hr />
<!-- insert image here -->
<?php
require("CordaEmbedder.php");
$myImage = new CordaEmbedder();
$myImage->externalServerAddress="<server_address>:2001";
$myImage->internalCommPortAddress = "localhost:2002";
$myImage->imageTemplate = "image_templates\examples\bar.itxml";
$myImage->width = 600;
$myImage->height = 400;
$myImage->pcScript = "title.setText(Hello World)";
echo $myImage->getEmbeddingHTML();
?>
<hr />
<p>If you see an image above, congratulations. You have successfully embedded your first image.</p>
</body>
</html>