This small tutorial will explain how to use and why you should use value objects troughout your Flex/AMFPHP projects.
First of all, we start with a simple php value object class:
class VOUser {
var strUsername = "";
var strEmail = "";
var $_explicitType = "com.isageo.VOUser";
}
Using the $_explicitType we tell AMFPHP to which value object class it should get mapped.
Next we create a simple php class that returns some VOUser objects:
class User {
public function getUser() {
// Get user using fancy database connection
$objUser = new VOUser();
$objUser->strUsername = "Georges";
$objEmail->"email@email.com";
return $objUser;
}
}
So now we have a simple service that gets called by the flex application and receives an VOUser object to work with. Let’s get back to Flex and create a VOUser class using ActionScript:
package com.isageo {
[RemoteClass(alias="com.isageo.VOUser")]
[Bindable]
class VOUser {
public var strUsername : String;
public var strEmail : String;
}
}
The RemoteClass meta data tells Flex where to find the VOUser class trough AMF. The next step is to receive some data from AMFPHP. So now when receiving a VOUser object from AMFPHP, Flex know exactly what properties it has and vice versa. Plus: when loading data directly into a Flex component and back out, Flex always retains the right object class (in this case VOUser).
So no more object conversions. You always get what you are expecting!