Flex and PHP: remoting with WebORB

Whenever you want to do remoting, you need a server-side library that will handle that part of communication. For PHP backends you have a choice of four libraries: Zend AMF (the latest on this stage), AMFPHP, WebORB for PHP, and SabreAMF. I’ve already written articles on two of them, AMFPHP and ZendAMF. In this post I will focus on WebORB. Next, I will play with SabreAMF, and I will finish this series with an article comparing them.

You can download a Flex Builder project that contains the code for this article from here. Inside of the archive you will find a readme.txt file explaining what to do with it.

Installing WebORB for PHP

After downloading WebORB for PHP (you need to register first), just extract the files somewhere on your computer. Next create a folder called weborb inside of your PHP web server, and then copy the content of the archive you’ve just extracted into it. You should end up with a folder that have a bunch of folders and files (see the Figure 1).

folders_weborb

Figure 1. Folder structure of WebORB for PHP.

WebORB comes with a lot of examples, and it also comes with a console that let’s you do a lot of things, including learning the basics of WebORB, seeing the available services exposed by WebORB, accessing the many Flex sample applications that came with WebORB (see Figure 2). You can find much more more information on this page.

weborb_console

Figure 2. WebORB console.

What is AMF and remoting and why should you use it?

If you already know these answers, you may want to skip to the next section. Let’s start by understanding remote procedure calls. Remote procedure calls let Flex applications  make direct calls on the methods of your server side classes. Using BlazeDS or LiveCycle Data Services you can expose your Java and ColdFusion classes to the Flex application. However, if you use PHP you need a third party library on the server to expose PHP classes directly. Existing solutions include Zend AMF, WebORB, and AMFPHP. AMF is a binary protocol for serializing the messages. Because it is binary, it is more efficient in terms of bandwidth and server processing load than JSON or XML methods. If you want to see for yourself how much more efficient it is, James Ward has put together a nice benchmark.

WebORB is a PHP library that knows how to serialize and deserialize the AMF protocol, and thus lets you expose PHP classes to Flex applications. Another compelling reason for using remoting is code reuse. Because you can call methods on PHP classes and these methods can return PHP objects, you don’t have to modify your existing code to output JSON or XML.

As I noted earlier, WebORB remoting uses AMF to serialize messages between the server and Flex client. It also offers the ability to map an ActionScript class to a PHP class. For example, suppose you want to display in Flex the information from a table with the following structure:

   1: contacts
   2: -------------------------------
   3: id      primary key int
   4: name    varchar(255)
   5: email   varchar(255)

When using remoting, you create an ActionScript class to model this data in the client and a PHP class to model the same data on the server. When you create the PHP class that you want to call from Flex, you add a method that, for example, retrieves all the contacts from the table. This method will return an array of PHP VO classes, and in Flex you will get an array of ActionScript objects. All the conversions from PHP objects to AMF to ActionScript objects are done automatically for you by  Flex and WebORB.

When you use XML or JSON for remoting, you’ll typically need extra steps in Flex to process the data in order to display or store it.

Let’s look at a working example.

Create the Flex PHP project

Usually, when I work with Flex and PHP projects, I prefer to use Flex Builder and Zend Studio installed together. It is possible, however, to work with Flex Builder and a PHP plugin to help you with the PHP code. Either way, you should create a Flex project that uses PHP on the server side (if you plan to use Zend Studio and Flex Builder, first create a Zend PHP Project, then use the Add Flex Nature wizard to add Flex PHP nature on the project). This way you streamline the deployment of the SWF file (the compiled result of the Flex project) to the PHP server. I chose to create a new project called “flex_weborb”.

Choose New > Folder, and then click on the Advanced button, and select the option Link to folder in the file system. Next, click the Browse button and chose the weborb folder you created earlier (the folder that holds the content of the WebORB archive).

Create the PHP code

All the PHP classes you want to expose to the Flex client need to be inside of the folder weborb/Services. If you navigate to this folder, you will find a bunch of files already in there. These are the services used by the samples that come with the framework. It is possible to separate the files in folders created inside of the Services folder. So you can have a class that is inside of a folder weborb/Services/org/corlan/utils/. Another thing, usually you use a VO to wrap one piece of information. This could be stored inside of the same weborb/Services folder. You don’t have to do anything special to configure the VO, you just place it under the weborb/Services folder, and use it inside of your PHP service class.

In the “weborb/Services” folder, create a PHP file called MyService.php, and in the folder weborb/Services/vo create a PHP file called VOAuthor.php. Open the MyService.php page and paste the following code (you need to update the connection information for your specific database setup; to do this, look for the four constants at the top of the class):

   1: <?php
   2: require_once ('vo/VOAuthor.php');
   3:
   4: //conection info
   5: define( "DATABASE_SERVER", "localhost");
   6: define( "DATABASE_USERNAME", "mihai");
   7: define( "DATABASE_PASSWORD", "mihai");
   8: define( "DATABASE_NAME", "flex360");
   9:
  10: class MyService {
  11:
  12:     public function getData() {
  13:         //connect to the database.
  14:         $mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
  15:         mysql_select_db(DATABASE_NAME);
  16:         //retrieve all rows
  17:         $query = "SELECT id_aut, fname_aut, lname_aut FROM authors_aut ORDER BY fname_aut";
  18:         $result = mysql_query($query);
  19:
  20:         $ret = array();
  21:         while ($obj = mysql_fetch_object($result, "VOAuthor")) {
  22:             $ret[] = $obj;
  23:         }
  24:         mysql_free_result($result);
  25:         return $ret;
  26:     }
  27:
  28:     public function saveData($author) {
  29:         if ($author == NULL)
  30:             return NULL;
  31:         //logMe($author);
  32:         //connect to the database.
  33:         $mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
  34:         mysql_select_db(DATABASE_NAME);
  35:         //save changes
  36:         $query = "UPDATE authors_aut SET fname_aut='".$author->fname_aut."', lname_aut='".$author->lname_aut."' WHERE id_aut=".  $author->id_aut;
  37:         $result = mysql_query($query);
  38:         return NULL;
  39:     }
  40: }
  41:
  42: function logMe($var) {
  43:     $filename = dirname(__FILE__) . '/__log.txt';
  44:
  45:     if (!$handle = fopen($filename, 'a')) {
  46:         echo "Cannot open file ($filename)";
  47:         return;
  48:     }
  49:
  50:     $toSave = var_export($var, true);
  51:        fwrite($handle, "[" . date("y-m-d H:i:s") . "]");
  52:     fwrite($handle, "\n");
  53:        fwrite($handle, $toSave);
  54:     fwrite($handle, "\n");
  55: }
  56: ?>

This is the class you will call from Flex. It has two methods: one to get all the records from the table, and another to update the values for one record.

Let’s create the code for the Value Object, the data model. This is used by the MyService class to wrap one row from the table. Thus, the method getData() returns an array of VOAuthor, and the method saveData() receives one argument: the VOAuthor of the row that was changed. Open the file VOAuthor.php and add this code:

   1: <?php
   2: class VOAuthor {
   3:      public $id_aut;
   4:      public $fname_aut;
   5:      public $lname_aut;
   6: }
   7: ?>

As you can see, this class is very simple; it just provides the same members as the fields from the table.

Creating the Flex application

Now, that you have the PHP code in place, you are ready to create the Flex code that will call the PHP class. I want the Flex application to have a button that gets the data from the server, uses a data grid to display the data, and enables the user to edit any cell (with the exception of the id field) within the data grid. Whenever a cell is edited, the update is sent automatically to the server and saved to the database as well.

First, be sure to select the Flex perspective from the top right icons of Eclipse.

The next thing you need to do is to configure the destination on the server in order to make calls to PHP classes from Flex. WebORB comes with all these configuration files created. If you go to the weborb/Weborb/WEB-INF/flex folder, you will find these files: services-config.xml, remoting-config.xml, and messaging-config.xml. First, you need to open the services-config.xml file and locate the opening node <channels>, and add after this code (pay attention to the uri attribute of the endpoint node; in my case the URL to weborb.php is http://localhost/weborb/weborb.php, though on your machine it could be different):

   1: <channel-definition id="my-amf-weborb" class="mx.messaging.channels.AMFChannel">
   2:        <endpoint uri="http://localhost/weborb/weborb.php" class="flex.messaging.endpoints.AMFEndpoint"/>
   3:        <properties>
   4:            <polling-enabled>false</polling-enabled>
   5:        </properties>
   6: </channel-definition>

Save the file, and then open the remoting-config.xml file, and add a new destination:

   1: <destination id="GenericFlexDestination">
   2:     <channels>
   3:       <channel ref="my-amf-weborb"/>
   4:     </channels>
   5:     <properties>
   6:         <source>*</source>
   7:     </properties>
   8: </destination>

You use this destination from Flex to make calls to the PHP services stored in the weborb/Services folder. You need to configure the Flex application to use  the services-config.xml configuration file. To do that, open the properties panel for the project (right click the project name, and choose Properties), click on Flex compiler, and add a new command –services and the absolute path to services-config.xml file (see Figure 3).

properties_weborb

Figure 3. Adding the -services compiler argument.

Click OK, and now you are ready to write the Flex code. Open the file flex_weborb.mxml if you haven’t already opened it, and paste this code:

   1: <?xml version="1.0" encoding="utf-8"?>
   2: <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
   3: <mx:Script>
   4:     <![CDATA[
   5:         import mx.controls.Alert;
   6:         import mx.rpc.events.FaultEvent;
   7:         import org.corlan.VOAuthor;
   8:         import mx.events.DataGridEvent;
   9:         import mx.rpc.events.ResultEvent;
  10:
  11:         private var item:VOAuthor;
  12:
  13:         private function init():void {
  14:             myRPC.getData();
  15:         }
  16:         private function getDataListener(event:ResultEvent):void {
  17:             dg.dataProvider = event.result;
  18:         }
  19:         private function editListener(event:DataGridEvent):void {
  20:             item = event.itemRenderer.data as VOAuthor;
  21:         }
  22:         private function saveDataListener(event:ResultEvent):void {
  23:             item = null;
  24:             init();
  25:         }
  26:         private function saveData():void {
  27:             if (item == null)
  28:                 return;
  29:             myRPC.saveData(item);
  30:         }
  31:         private function faultListener(event:FaultEvent):void {
  32:             Alert.show(event.fault.faultString);
  33:         }
  34:
  35:     ]]>
  36: </mx:Script>
  37:
  38: <mx:RemoteObject id="myRPC" destination="GenericFlexDestination" source="MyService" fault="faultListener(event)">
  39:     <mx:method name="getData" result="getDataListener(event)"/>
  40:     <mx:method name="saveData" result="saveDataListener(event)"/>
  41: </mx:RemoteObject>
  42: <mx:VBox>
  43:     <mx:DataGrid id="dg" editable="true" itemEditEnd="editListener(event)" />
  44:     <mx:Button label="Save" click="saveData()" />
  45:     <mx:Button label="Get Data" click="init()" />
  46: </mx:VBox>
  47: </mx:Application>

I use the mx:RemoteObject to make the calls to the MyService PHP class from the server:

   1: <mx:RemoteObject id="myRPC" destination="GenericFlexDestination" source="MyService" fault="faultListener(event)">
   2:     <mx:method name="getData" result="getDataListener(event)"/>
   3:     <mx:method name="saveData" result="saveDataListener(event)"/>
   4: </mx:RemoteObject>

The destination attribute has the same value as the id value of the destination defined in the remoting-config.xml file (thus I am telling Flex that this is the destination I want to use). The source attribute points to the PHP class for which I want to make the calls. If the PHP class would have been in a folder that is in the Services folder, than I would use the folder names before the PHP class name with dot notation. For example, if you have MyService in weborb/Services/org/corlan, then the value of the source attribute is org.corlan.MyService.

Next I have defined the two methods I want to call on the PHP class (getData() and saveData()), and I set the result listeners for each method (these are the functions that will be called once the Flex application receives the response from the server).

For the UI I am using a DataGrid to display the data and edit inline the two text fields (first name and last name). I have a button to trigger the saving of the data back to server. On the DataGrid I have another listener registered for the end editing event, and the function registered gets called whenever something is edited in the DataGrid.

As you remember, I use a PHP object (VOAuthor) to wrap each row from the table. And I said that with remoting it is possible to get the conversion automatically from the PHP type to the proper ActionScript type. To do this, all you need to do is to create the ActionScript object. So just create a new ActionScript class with the package org.corlan, and the name VOAuthor. Paste this code in the class:

   1: package org.corlan {
   2:
   3:     [RemoteClass(alias="vo.VOAuthor")]
   4:     [Bindable]
   5:     public class VOAuthor {
   6:
   7:         public var id_aut:int;
   8:         public var fname_aut:String;
   9:         public var lname_aut:String;
  10:     }
  11: }

As you can see this class has the same members as the PHP class. It is very important to set the correct value for the alias attribute from the RemoteClass metatag. This tag tells the Flex application to what the corresponding server-side class is for this ActionScript class. In this case, the value vo.VOAuthor means that in the weborb/Services, there is a vo folder, and inside of it there is a VOAuthor PHP class.

And with that you should be ready to run the project and edit the data. To edit the data, just double click inside of a cell (see Figure 4).

weborbapp

Figure 4. The application with sample data.

Conclusion

WebORB handles the remoting as well as all the other frameworks. So there is nothing spectacular here. However, WebORB for PHP offers more than remoting. First of all, it offers data messaging (Publisher/Subscriber), so you can implement a chat or some other application that needs to push updates to all the connected clients. Though, I must say the only solution supported for PHP is AMF polling. Which means that the client does a request to the server from time to time to see if there is something new. This is a limitation of the PHP servers, as it would be very hard to implement a real data push over an open channel (COMET style maybe?). For example, for Java and ColdFusion servers you can have data pushing using polling or the RTMP protocol.

Secondly, WebORB comes with tons of sample applications, and a console that eases the testing of the services and lets you play with the samples. And finally, using the same console, you can generate some ActionScript code for any service. Basically, it generates a wrapper for the RemoteObject, and an ActionScript object for each of the VO used on the server. However, I didn’t find this to be very helpful, because it doesn’t generate for example the VOAuthor that I used in my example, but instead something like this:

   1: package
   2:    {
   3:      [Bindable]
   4:      public class MyServiceModel
   5:      {
   6:            public var getDataResult:Object;
   7:            public var saveDataResult:Object;
   8:
   9:      }
  10:    }

47 thoughts on “Flex and PHP: remoting with WebORB

  1. Thanks for the article. I would like to add to your conclusion that Weborb supports long polling, which will help reduces the number of request to the server significantly. Not to mention RTMP is supported as well.

    Weborb also have their own authentication mechanism, whereby developers have to set a “credential” to successfully make calls to the server. I’m not sure the others have this. Let me know if you will.

    I uses Weborb in my proxy server to pass data to my Flash content in situation where cross-domain file is not available on the external domain. Just did a mini-project that hooks up with the Friendfeed API.

    Check it out. http://alekkus.com/blog/2009/02/hooking-up-to-friendfeed-api/

  2. Hi Mihai, I’ve used this article to understand Zend AMF and it has helped me implement it in my app, thank you so much. I am having one difficulty though, one of the objects returned is of type Date, however, when I try to use a DateField as an itemEditor for this object I get an error saying it cannot convert it from the String. Please have a quick look at my code below and tell me if I’ve missed something obvious.

    The DataGridColumn in MXML:

    The ActionScript class:
    package includes
    {
    [RemoteClass(alias="VOTrailer")]
    [Bindable]
    public class VOTrailer
    {
    public var id:int;
    public var adr:Boolean;
    public var label:String;
    public var type:String;
    public var loc_street:String;
    public var loc_city:String;
    public var loc_country:String;
    public var dest_street:String;
    public var dest_city:String;
    public var dest_country:String;
    public var start_date:Date;
    public var end_date:Date;
    public var space:int;
    public var description:String;
    public var notes:String;
    public var timestamp:Date;
    public var company_id:int;

    }
    }

    The error:
    TypeError: Error #1034: Type Coercion failed: cannot convert “24/12/2009″ to Date.

  3. hmmm, the comment above did not include the MXML, must be a security thing. Here it is without the tags:

    DataGridColumn headerText=”Start Date” dataField=”start_date” itemEditor=”mx.controls.DateField” editorDataField=”selectedDate”

  4. @conor

    I have similar issue before. Have you checked taht your timestamp attribute in PHP is a date object?

    If so, then this is a serialization issue. The Date object in Flex expects a string format like “2009/12/24 18:00:31 GMT+0800″, hence “24/12/2009″ doesn’t comply to that.

    You can change the timetamp data type on both sides to String/Number, representing the timestamp using Unix format. Then on Flex side, whenever you need to display the timestring, use new Date(timestamp).toDateString().

    Hope that helps.

  5. hey alekkus, thanks for the help, sorry I’m kinda new to this object oriented approach to php, here is the php class definition

    <?php
    class VOTrailer {
    public $id;
    public $adr;
    public $label;
    public $type;
    public $loc_street;
    public $loc_city;
    public $loc_country;
    public $dest_street;
    public $dest_city;
    public $dest_country;
    public $start_date;
    public $end_date;
    public $space;
    public $description;
    public $notes;
    public $timestamp;
    public $company_id;
    }

    do i need to typecast each var?

  6. @conor

    alekkus gives you a solution, for using timestamp format in the PHP side. or you can play around setter and getter for the date fields. For example (assuming):

    public class VOTrailer
    {

    private var _timestamp:Date;

    public function set timestamp(timestamp:String):void{
    _timestamp = new Date(date);
    }
    public function get timestamp():Date{
    return _timestamp;
    }

    }

  7. Mihai, do you think you could do a simple tutorial on exchanging dates between MySQL, PHP and Flex?

    From several days of searching I’ve failed to find an elegant solution, what you’ve suggested above may well work but I’m still a beginner really and I’m struggling to implement it.

    Thanks, Conor.

  8. Hey Mihai, well let me describe my problem. I have an object in flex which has a property of type Date. Using Zend AMF I also have the same object defined on the server side in php and I transfer this data as a RemoteObject. The difficulty I have is storing the ‘Date’ information in the MySQL database in a format which can easily be exchanged with Flex.

    For all other properties, int, String, Number etc. the data can be saved in MySQL in the format received from Flex, but not for the Date type. MySQL dates have a different format so should I store as a number/string or some other format?

    What I would like to understand is this: What is the best way to store a Flex Date object in a MySQL database so that it is easy to pass Date values to and from MySQL and Flex using Remote Objects with Zend AMF.

    It would be fantastic if you could demonstrate a working method as I have struggled for several days to find and adequate solution.

    Thanks, Conor

    ;)

  9. @conor

    As mentioned in my previous comment, I would suggest you using Unix timestamp format. That means you use int/Number as the data type. In this way, you can compare dates easily using SQL statements when comparing dates. Also, since it’s an int, sending it to Flex will not pose any problem.

    On your Flex end, just call new Date() to create a Date object.

  10. OK alekkus, I will try to get this to work again using UNIX format.

    I am using an array of the returned objects as a dataprovider for a datagrid. So the server sends the unix timestamp to flex as a number, flex expects a Date. At what point should the conversion to Date object be done?

  11. @conor

    On flex end, use Number data type for your object. Then use labelFunction on the column to convert the timestamp to date. Here’s the source codes:

  12. Hi guys, alekkus, I used your convertToDate function to display the unix time date from the server and it worked fine. My problem now is changing the date. The date column is using a DateField as an itemEditor but when I click on the field to edit it I get an error saying that it cannot convert the unix time value to a date.

    (TypeError: Error #1034: Type Coercion failed: cannot convert 1175001854629 to Date.)

    Do I need to write a function for this also? It seems odd that Flex does not do this automatically since it can display the date.

  13. I am sorry to keep asking guys, I still cannot solve this. I need to understand something. If I send a value object from Zend AMF to Flex with a Number property for the date in Unix time how do I

    a: get the dataGrid to render the date as a date instead of the number

    b: get the DateField itemEditor to use the rendered date and allow me to save the chosen date back to the Number type

  14. I think I need to use getters and setters like you suggested Mihai. I also believe I need to use these in my VO object class.

    Here is my current class:

    [RemoteClass(alias="VOLoad")]
    [Bindable]
    public class VOLoad
    {
    public var id:int;
    public var adr:Boolean;
    public var label:String;
    public var loc_street:String;
    public var loc_city:String;
    public var loc_country:String;
    public var dest_street:String;
    public var dest_city:String;
    public var dest_country:String;
    public var start_date:Date;
    public var end_date:Date;
    public var space:int;
    public var weight:int;
    public var description:String;
    public var notes:String;
    public var company_id:int;
    }

    When I receive this back from the server I create an arraycollection with the returned objects as follows

    myLoadDP = new ArrayCollection(ArrayUtil.toArray(event.result));

    then I use this arraycollection as a dataprovider for my datagrid. I want to get the start_date and end_date fields to render in the dataGrid but also be editable with a dropin itemEditor. I have and event trigger on the oneditend event on the datagrid to save the data back to the server and this is why I need to send the date back to mysql in the same format I fetched it in. My application is very similar in function to the one you created here Mihai, maybe you could add a Date column to this and expand the tutorial? Pretty please? ;o)

  15. Pingback: Flex Monkey Patches » Blog Archive » Rubbernecker’s Review - Week 29 - (Adobe Flex/Flash/AIR/LCDS Blog post recap)

  16. thanks for the article. However, I’m a php ZF developer, looking to start using flex as the client-side.

    Will there be any articles on using the ZF and ‘adding on’ the flex frontside? I like the ZF mvc structure and would like to keep using it in development.

    Thanks

  17. @Tjorriemorrie

    I will play a little bit with the ZF and Zend AMF. What would you like to see?

    Regarding MVC in the context of Flex and PHP with Zend Framework, here the things are a little bit different compared to “traditional” web apps (HTML).

    Flex is a SOA technology. As a result, when you create a Flex application that brings data from the server, you’ve already achieved some MVC: you have a clean separation between the presentation of the data (the Flex client), and the Server side (business logic/persistance layer in DB).

    However, usually you go a little bit further, by implementing MVC in the Flex side too, especially with large projects or teams.

  18. Pingback: Flex and PHP: remoting with SabreAMF : Mihai CORLAN

  19. Is there a way to typecast the values in the php VO? For example, if I send through a boolean field from amfphp to flex, it goes through as “0″ or “1″ (i.e. strings), whereas a true boolean would be 0 or 1 (i.e. an int).

    I know that I could loop through the array in php manually, but this seems a bit clumsy. Is there a way to specify the variable type in the actual php VO?

  20. are you returning the data from the database?

    If so, set your value as a boolean in php as follows

    if ( $row->mybool == 0 ){
    $row->mybool = false;
    }else{
    $row->mybool = true;
    }

  21. As I said, I know that I can loop through and assign each variable type manually, but its clumsy at best. I was also just using bool as an example, but in fact amfphp typecasts any number (int, float, bool) as a string.

    My question remains: Is there a way to specify the variable type in the VO?

  22. Not in PHP, PHP does not support explicit type definition in variable declarations

  23. The type is set based on the context when you set the variable as follows:

    //define variable as a string
    myvar = “true”;

    //define variable as a boolean
    myvar = true;

  24. 2Jon:

    I’ve used the VO constructor to set data type.
    However I’ve found that when using mysql_fetch_object, the constructor gets called after data initialization :O)
    Anyway, this approach works and saves data fetching functions from ugliness :O)

    class gDataVO {
    public $id;
    public $name;

    public function __construct() {
    settype($this->id, “integer”);
    }
    }

  25. PS: __set override does not work also. At least I have not managed to do it that way.

  26. My understanding of settype is to convert a variable which has a value already rather than to set a variable to a particular type. So as I understand it, if you set id as an integer as motorro shows above but you subsequently set id as follows:

    $id = “1″;

    id is now a string, despite you setting its type to integer.

  27. 2 conor:

    1) Yes, if you do the following:
    $a = 1;
    $a = “1″;
    the type of $a is back a string (unfortunately).
    As I’ve said the constructor gets called after member initialization – so the type is converted after the data is set. More accurate way will be:

    class dataVO {
    public $id;
    public function convert() {
    $this->id = intval($this->id);
    }
    ….
    $r = mysql_fetch…
    $r->convert();

    }

    2) You can use any type cast operation you like for example:

    $a = (int)$a;
    $a += 0;
    settype($a,$type);

    Any of that method gives the same result (IMHO)
    except that settype gives you the opportunity to perform:

    $vars = array (“String”, “123″, “0″);
    $types = array (“string”, “integer”, “boolean”);

    for ($i = 0; $i < 3; ++$i) {
    settype($vars[$i], $types[$i]);
    }

    PS: The fastest way considered to be $a += 0;

  28. Motorro: I tried your method of using:

    public function __construct() {
    settype($this->id, “integer”);
    }
    }

    And it works perfectly! Thank you.

    How much extra overhead is incurred using this method?

  29. Pingback: Flex and PHP: remoting with WebORB : Mihai CORLAN « DevEzine

  30. Hi Mihai. I’m a weborb-php 3.5′s user. When I try to build a model and, in my database exists a VIEW under MySQL, I got a validation error. A primary key is required. How can solve this problem?
    Thanks

  31. Hi there,

    I have developed a Flex app with .NET webservices as the
    backend. Webservices are deployed beind firewall. How can I access
    those webservices from my client side Flex app.

    Can I access using proxie using Weborb? If so what is the edition I
    need to use. Can any body guide me in this issue?

    thanks
    vin

  32. @vin

    I’m sure that you’ll find the solution or advices if you take a look at WebORB website and forum.

  33. hey i tried the above and am getting a funny error. ideally, you should be able to have folders within WebORB/Services to organize your php classes and such..

    so, i have stated a remote object with destination id = “genericdestination” and source = “com.myapp.Login”

    when i run the app, i get an error saying: unable to load file C:/…/WebORB/Services/genericdestination.php

    apparently, it is looking at the destination id in the services-config.xml file to locate the class with the same name which is weird…

    i expected it to look for WebORB/Services/com/myapp/Login.php

    any thoughts?

  34. i have installed weborb on XAMPP in the htdocs
    folder the console opens ok and the data management
    reads Mysql tables fine, when i add a database
    like the foodAndDrink i get this message from the Data Management
    faultCode:Client.Error.DeliveryInDoubt faultString:’Channel disconnected’ faultDetail:’Channel disconnected before an acknowledgement was received’

    Can you help me please

    Regards

    Jorge

  35. Hi All,

    Please i have question concerning deployement of flex application with Weborb and PHP.
    I want to know if it is possible to install Weborb and my PHP to another server instead of installing this on the same web server where *.swf files are?

    So in that case i will have tow separated web server, the first with my flex application (user interface) and the other server with Weborb and php code.

    Thanks for your help,
    Euloge

  36. Hello,
    is there a way to access $GLOBALS from within your method other than require(‘globals.ini’) separate file.
    Try the following code. I was expecting to get as a return value “my global variable”, but instead, i get NULL.

  37. Hello, Thanks for the post. It was very usefull. Howe ever I had only half luck. I slightly modified the code and added addData($userinfo) which passes a vo object containing user info and it has insert into statements. but I am getting below err
    Error: “Channel disconnected before an acknowledgement was received”

    Can you help me how to fix this? I am new to flex

  38. @Mrd

    Most likely you have PHP error in your class. try to execute the PHP class method in browser directly and make sure you don’t have an error.

    cheers,
    Mihai

  39. This was really an outstanding example, which i am sure gonna help me out during my development as am new to flex with php

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>