Getting Started with WebORB for PHP
Search:
WebORB for PHP provides a Flex Remoting and Flex Messaging 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 and 3 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:

┬  WEBORB Installation directory

├── index.php
------- management console point of entry

├── weborb.php
------- main PHP script - place it into the 
│                      same directory where your compiled SWF
│                     
are located and adjust paths in the
│                     
require_once calls in the file

├── /Services
------- contains deployed 'remotable' PHP classes

├── /examples
------- contains examples shipped with WebORB

├── /Console 
------- contains WebORB Management Console
│     │     
│     ├─ index.php 
----- main console page
│     │     
│     └─ weborb.php 
----- remoting entry point for the console

├── /weborbassets
│     │     
│     └─ weborb.swc 
----- client-side class library,
│                          required for messaging apps

└── /Weborb  
------- contains configuration, log and
     │               WebORB for PHP source code
     │     
     ├─ weborb-config.xml 
----- contains a reference to the
     │                           /Services folder, as well as other
     │                          
important weborb configuration 
     │
     └─ /WEB-INF
         │     
         └─ /flex
           │     
           ├─ remoting-config.xml
 -- configures Flex destinations
           ├─ messaging-config.xml
 -- configures Flex messaging
           │                          
destinations
           └─ services-config.xml 
-- configures Flex RPC endpoint

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.

You can verify the installation by running WebORB Management Console included with the WebORB distribution.  Open http://localhost/[WEBORB INSTALL PATH]/index.php in a browser. When the console is loaded, you can inspect available PHP remoting services using the Management tab or run the examples included with the product.

GETTING STARTED - CREATING A FLEX APPLICATION

The instructions below will guide you through the process of creating and running a remoting-enabled Flex application using Flex Builder 3. At the end of the walkthrough you will have a Flex application communicating with a PHP object exposed through WebORB.

Run Flex Builder 3 and select File -> New -> Flex Project.  The dialog window shown below will appear. Enter "SampleFlexToDotNetProject" as the project name. Make sure to select "PHP" as the Application server type. Make other selections as shown below and click "Next >".

The next step is very important as it establishes the configuration paths. For the simplicity of instructions, assume WebORB is installed in the c:\dev\WeborbPHP\ folder. The WeborbPHP folder is also mapped as a virtual directory in the webserver. There are two paths to specify in the next step: Web root and Root URL:

Web root - this is a directory that contains an installation of WebORB.
Root URL - this is a URL corresponding to the "Web root" directory.

Click "Finish" to continue. Flex Builder creates a default (blank) Flex application.

Right click the project node in the "Flex Navigator" panel and open Properties. Select "Flex Compiler" and enter the following parameter into the "Additional compiler arguments" as shown in the image below:

-services c:\[WEBORB_PATH]\Weborb\web-inf\flex\services-config.xml

In case when WebORB is installed in c:\dev\WeborbPHP, the path would be:

-services c:\dev\WeborbPHP\Weborb\web-inf\flex\services-config.xml

Click OK to close the window.

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_PATH]\Weborb\WEB-INF\flex folder. The application in this example uses the "InfoService" destination defined as:

 <destination id="InfoServiceDestination">
   <properties>
     <source>InfoService</source>
   </properties>
</destination>

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:

<?php 
   require_once("../Weborb/ORBHttpHandler.php");

   $m_ORBHttpHandler = new ORBHttpHandler();
   $m_ORBHttpHandler->processRequest();
?>

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. 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:

remoteObject = new RemoteObject();
remoteObject.destination = "InfoServiceDestination";
remoteObject.getComputerInfo.addEventListener("result", onResult);
remoteObject.addEventListener("fault", onFault);

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:

private function getInfo():void
{
  invokeButton.enabled = false;
  currentUserText.text = "";
  processIdText.text = "";
  osText.text = "";
  phpVersionText.text = "";
  remoteObject.getComputerInfo();
}

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:

private function onResult(event:ResultEvent):void
{
  var computerInfo:Object = event.result;
  currentUserText.text = computerInfo.currentUser;
  processIdText.text = computerInfo.phpProcessId;
  osText.text = computerInfo.operatingSystem;
  phpVersionText.text = computerInfo.phpVersion;
  invokeButton.enabled = true;
}

The source code for the server-side object is below:

class InfoService
{
  public function getComputerInfo()
  {
    $compInfo = new ComputerInfo();
    $compInfo->currentUser = get_current_user();
    $compInfo->phpProcessId = getmypid();
    $compInfo->operatingSystem = php_uname( 'a' );
    $compInfo->phpVersion = phpversion();
    return $compInfo;
  }
}

class ComputerInfo
{
  public $currentUser;
  public $phpProcessId;
  public $operatingSystem;
  public $phpVersion;
}

 


WebORB is Open Source and FREE
 

Check out product support packages

Product Information

 

Development Resources

 

Licensing and Purchasing

 
Copyright © 2003-2008 Midnight Coders, Inc.  Privacy Policy | Contact Webmaster
Home | Products | Customers | Download | Licensing| Forum | About