Getting started with WebORB for PHP
WebORB for PHP provides a
Flex Remoting implementation. Using WebORB, PHP developers can
integrate Flex client applications with objects
deployed in PHP applications. Additionally, WebORB
for PHP can function as a Flash Remoting gateway
thus supporting Flash client applications. This guide provides an overview of creating a Flex client using Flex Builder 2.0 and connecting it with a PHP application. The result of the walkthrough is a Flex application communicating with a PHP object exposed through WebORB for PHP. |
||||
GETTING STARTED - WEBORB INSTALLATION | ||||
WebORB for PHP installation has the following directory structure:
If you are deploying on a Windows computer with IIS,
make sure to grant Read/Write permissions to the IUSR_<machinename>
account for the /Weborb folder. |
||||
GETTING STARTED - CREATING A FLEX APPLICATION | ||||
Start Flex Builder 2.0 and select File -> New -> Flex Project. A dialog window shown below will appear. Make the selections as shown below and click "Next >".
The next step is very important as it establishes the configuration paths. Uncheck the 'Use default location..' checkbox. The 'Root folder' field must contain the path to the /Weborb folder from the WebORB for PHP distribution. The 'Root URL' field must contain a URL pointing to the same /Weborb folder: Click "Next >" to continue.
The next step is to assign a name to the Flex project. Enter "SampleFlexToPHPProject" for the project the name as shown below and click 'Next' to continue.
The final step in Flex project creation is to set the output folder path and output folder url. Both of these values must point to a folder in the web server hierarchy. It is important that both 'Output folder' and 'Output folder URL' point to the same directory. Click 'Finish' to finalize project construction.
Flex Builder creates an empty Flex application. The
steps below will guide through building a Flex
application and connecting it with a PHP object. |
||||
CONFIGURATION - FLEX BUILDER | ||||
WebORB for PHP product distribution contains a finished Flex application demonstrating Flex to WebORB connectivity and a remoting invocation. Copy and paste the contents of the example.mxml file located at \Examples\SampleApp\ into the mxml file created in Flex
Builder. The code in the application connects to a PHP
object and retrieves some basic information about the
computer where the object is running. |
||||
CONFIGURATION - WEBORB | ||||
Flex applications require a declaration of the exposed classes as "destinations". Destinations must be configured in remoting-config.xml located in the \Weborb\WEB-INF\flex folder. The application in this example uses the "InfoService" destination defined as:
Flex Builder loads the configuration file during the compile time. IMPORTANT: Make sure to locate the directory where Flex Builder places the compiled client application. It is very important to place a copy of weborb.php into the same directory. weborb.php must contain the following PHP code:
VERY IMPORTANT: The first line must be edited to point to the Weborb directory from the product distribution. For example, look at weborb.php located in the /Console folder |
||||
RUNNING FLEX APPLICATION |
||||
When you run the application in Flex Builder, it opens a browser and loads the application from: http://localhost/Examples/SampleFlexToPHPProject.html The application connects to the backend
service upon the startup or when user clicks the "Send
Request" button: |
||||
CODE REVIEW | ||||
Flex application declares a remote object using the RemoteObject API:
Notice the destination name matches the destination entered in remoting-config.xml. When a user clicks the 'Get Computer Info' button, the following function executes a remote method invocation:
When an invocation response is available, Flex invokes a response handler specified in the <RemoteObject> tag. The response handler in the example, populates the text fields with the data available in the returned object:
The source code for the server-side object is below:
|