AMFPHP Class Mapping Primer [1.9 beta]
1 July 2008Thought I’d post a simple AMFPHP class mapping primer.
I ran into a wall after re-arranging my VO / DAO package structure on the server, learned a few things in the process and thought I’d post .
I’m assuming your using AMFPHP 1.9 beta.
Class mapping allows your php backend and actionscript frontend to pass strongly typed variables back and forth. The benefits are obvious so I won’t cover them here.
If your not after any detailed information here’s a quick set of samples classes to get you going.
PHP
// LoginVO.php is saved as {$voPath}/com/dl/app/LoginVO.php
class LoginVO
{
var $_explicitType="com.dl.app.LoginVO";
public $username;
public $password;
}
AS
package com.dl.common.Login.model.vo
{
[RemoteClass(alias="com.dl.app.LoginVO")]
public class LoginVO
{
public var username:String;
public var password:String;
}
}
That’s it. If your after more options and detailed info, keep reading.
Sending Strongly Typed Objects from PHP to ActionScript via AMFPHP
In PHP
You have a few options (choose one).
The most common approach is to use the $_explicitType class member:
class LoginVO
{
var $_explicitType="com.dl.app.LoginVO";
public $username;
public $password;
}
e.g.
$GLOBALS['amfphp']['outgoingClassMappings']['myclass'] = "com.dl.myapp.MyClass";
Note that the local class name associative key (’myclass’ above) must be in lowercase with the current release of AMFPHP.
If your install of PHP has the ReflectionAPI you can let AMFPHP do the work *for* you. I found a few cavets using this approach on servers who’s OS uses backslashes natively. If this is the case, AMFPHP will only send the name of the class and not include any package info. There are two simple code changes you can make in AMFPHP to get around this, just drop me a line if your interested (hopefully they’ll be commited in the next release of AMFPHP).
In actionscript
Here to, you have a some options,
package com.dl.common.Login.model.vo
{
[RemoteClass(alias="com.dl.app.LoginVO")]
public class LoginVO
{
public var username:String;
public var password:String;
}
}
registerClassAlias(”com.dl.app.LoginVO”,LoginVO);
Make sure your actionscript project contains a reference to the class. See my previous post for more info.
Sending Strongly Typed Objects from ActionScript to PHP via AMFPHP
In PHP
Rely on the class having been registed in ActionScript with the server’s correct package [directory] structure (relative to AMFPHP’s VO base path $GLOBALS[’amfphp’][’customMappingsPath’]). If this is the case you, your all set.
Define $GLOBALS[’amfphp’][’incomingClassMappings’][’remoteclassAlias‘] = ‘localclassPackage‘. (e.g. $GLOBALS[’amfphp’][’incomingClassMappings’][’com.dl.as3.userVO’] = ‘com.dl.userVO’);
In ActionScript
Again, you’ll need to use one of the two following…
For more info check out
AMFBaseSerializer.php’s getClassName() function
AMFBaseDeserializer.php’s mapClass() function










on August 19th, 2008 at 1:56 pm
Hey…I’m trying to do a composite in php that retuns an array of typed arrays, but i can’t.
i submit this article on a forum that has a print of a remote answer.
http://forum.flexbrasil.com.br/viewtopic.php?f=4&t=540&p=1928&hilit=composite#p1928
my application returns an object:LoginComposite but insite i have only objects:Object.
I’m trying to Send Strong Typed Objects but it doesn’t work.
on August 19th, 2008 at 7:23 pm
Roberto,
Can you post your AS3 and PHP classes / code that are not working?