Zend Amf Class Mapping
September 24th, 2008
The latest version of Zend Amf in the incubator has full support for type mapping of objects. Check out this screen cast, now w/ audio, that shows the there different ways that you can set the return type of an object when it comes back to flex. Thanks Kevin for the PHP classes for the example!
Zend Amf Class Mapping Adobe Mirror Thanks Lee Brimelow and Kevin Hoyt for the bandwidth from Adobe!
Zend Amf Class Mapping screencast I only have 2 gigs of transfer
If you have tried to work with the files in the incubator please update them as Class Mapping was not included in the last checkin.


Has any version of ZendAMF been ( publicly ) released. I’m really interested in checking it out.
@Alan There is not a public release. We are trying to get some of the alpha testers in the incubator up to speed as quickly as possible. The main advantage of Zend is it is a community driven project with lots of feedback and lots of test cases. We are working on both of those things in order to make sure it is supported on all platforms and meets the needs of the Zend user community.
Cool, got it running.
I am kinda stuck however, integrating it into a zend-framework project (using models and controllers)
Are there any examples? is it at all possible?
I know I’m early with these questions when things are still in alpha.
Regards
Patrick
I’m trying to work with the Incubator files myself, but I’m having no luck getting the result back into flex. Tried catching errors but it seems some of the class files are missing. You reference “Zend_Amf_Server_Fault” in the specs but I don’t see that. Do I have the wrong folder checked out? Any help would be appreciated.
Nevermind! I figured out that the demos in the proposal are dated. My fix was that I just had to
echo $server->handle();
instead of
$server->handle();
in the demo. So far so good! Just connected to a database and populated a DataGrid
Thanks for all the hard work, Wade.
Hey there,
excellent work! I got the files from the incubator up and running.
Works great.
But there is one thing i can not figure out, how would you send hierarchical data from php via amf to flex to fill a tree list?
Cheers,
Lx
Ok ,
got almost everything working now in an Framework project. Except for one thing:
Sending an Object {foo:”bar”} with encoding set to AMF3, results in an exception being thrown in request.php.
It does the same thing when I try to send an Array ["foo",bar"]. (AMF0, works just fine)
Sending a string does work.
Can anyone confirm? If so I’ll file a bugreport.
[ ZF version: 1.7 pre , php5.2.5 on OSX 10.5.5]
regards
Patrick
Dear Wade,
I saw you sreencast.
Have one question:
Why do you need to define class for returing Object in PHP and also in AS (Flex). I think its much easyer to use ObjectProxy, than to deal with classes in both places if only need to rename fields or add (remove) any.
I know that ObjectProxy defines one way bindig, but there is now so much data edited and to be saved to server. When editing data using ObjectProxy just:
[Bindable] var AR:Array = new Array();
[Bindable] var Contact_Now:ObjectProxy;
private function result_contact(evt:ResultEvent):void {
AR = evt.result.data_list;
}
private function DG_Change(e:Event):void{
Contact_Now = new ObjectProxy(e.currentTarget.selectedItem)
}
Much easyer and no headache with Classes.
Best regards,
Vitaly
Hi Wade
There is something wrong with your screencasts, can’t be watch!?
Any written tutorials on classmapping with Zend_Amf?
@pbohny click on the adobe mirror. There is a tutorial in XML format in the documents folder of the 1.7 prerelease it just has yet to be rendered.
I have successfully changed my Flex services from amfphp to zend_amf. Lee’s Tutorial also helped. I do know have this index.php
setClass(‘ClassOne’)
->setClass(‘ClassTwo’);
echo($server->handle());
?>
Is it correct that this actually takes over the part of gateway.php in amfphp?
You are recommending namespacing with a second argument like
$server->setClass(‘ClassOne’, ‘classOne’)
->setClass(‘ClassTwo’, ‘classTwo’);
What does it mean? How to add namespace to the classes? Put them into folders?
I do have collions with duplicate methods.
I too am having issues with duplicate methods. If one were to use NetConnection to connect and setClass on a few different classes, how do you add and call the function with the namespace? I have a basic Service class that all my classes extend and it throws duplicate errors since they all defined the protected/public functions again.
$server->setClass(new Service_Home(), ‘Service_Home’);
how do I call methodName() method of Service_Home with that namespace?
__nc.call(‘Service_Home.Service_Home.methodName’, __responder, params);
??
__nc.call(‘Service_Home.methodName’, __responder, params);
works great if I don’t add any other services or a namespace.
Hi Wade,
Do you have any example done in Flash CS3 using classmapping feature?
I tried mostly every possible combination, but onResult it always returns [object Object].. I checked the same classes in Flex and they return as they should.
Thanks
Sorry for the double post, I think I found my solution and perhaps might be useful for other people.
registerClassAlias(“ActionscriptVOClass_RemoteClass.alias”, ActionscriptVOClass);
needs to be called in order the register the class with RemoteClass.
Don’t know why it doesn’t need in Flex..
I want to parse AMF binary content to be able to make it readable by a human, without knowing what it is inside or who created the logics.
PHP Fatal error: Uncaught exception ‘Zend_Amf_Exception’ with message ‘Unable to parse /2/onResult body data com.mycompany.MyClass mapped class is not defined’ in /home/alexist/amf/Zend/Amf/Request.php:174
The error occurs because I do not know what kind of class is “com.mycompany.MyClass” but I still want to know what fields are inside and the rest of the response.
Is there a way to avoid to throw this exception and continue the parsing?
Thanks for the screen cast hove now got this working like a dream thanks, however i have come across one small problem and this is when trying to map nested arrays.
this is the php array which i am trying to send back to the client flex app
[1] => Table Object
(
[TABLE_NAME] => COUNTRY
[COLUMNS] => Array
(
[0] => Column Object
(
[COLUMN_NAME] => CODE
)
[1] => Column Object
(
[COLUMN_NAME] => NAME
)
)
)
when i debug event.result has the Table correctly mapped to TableVO as it should be but columns are empty, please can anyone shed some light on this as its driving me nuts.
PhP classes
class Table{
//public $_explicitType = ‘TableVO’;
public $TABLE_NAME = “”;
public $COLUMNS = array();
function Table($aa = null){
if($aa){
foreach ($aa as $k=>$v)
if(!is_numeric($k)){
$this->$k = $aa[$k];
}
}
}
public function getASClassName(){
return ‘TableVO’;
}
}
class Column{
//public $_explicitType = ‘ColumnVO’;
public $COLUMN_NAME = “”;
function Column($aa = null){
if($aa){
foreach ($aa as $k=>$v)
if(!is_numeric($k)){
$this->$k = $aa[$k];
}
}
}
public function getASClassName(){
return ‘ColumnVO’;
}
}
My Flex Classes are
package com.chr.vo
{
import mx.collections.ArrayCollection;
[Bindable]
[RemoteClass(alias="TableVO")]
public class TableVO
{
public var TABLE_NAME:String;
public var COLUMNS:ArrayCollection;
public function TableVO()
{
}
}
}
package com.chr.vo
{
[Bindable]
[RemoteClass(alias="ColumnVO")]
public class ColumnVO
{
public var COLUMN_NAME:String;
public function ColumnVO()
{
}
}
}
How do i correctly map the nested data please?
Thanks in advance
Hi, thanks Dear Wade Arnol.
have you the source code of screenshot ,pls if you have pls send via email or let me download it.
BR
farid valipour
Can anyone tell me if Zend AMF supports complex objects? For example, in my Flex app I have an Employee class that has an Address object as one of it’s public properties. The primitive typed properties of the Employee class are working, but so far I am unable to get Flex to recognize the address object. In the console I’m seeing this error:
TypeError: Error #1034: Type Coercion failed: cannot convert Object@62508a9 to valueObjects.Address
Any suggestions would be greatly appreciated. Also, I’m thinking ahead and wondering about how I would do something like using an ArrayCollection of custom data types (for example: create a public var inside my Employee class that is meant to hold an ArrayCollection of Address objects).
Thanks much,
@Lx
Hi Lx ,
Have you found solution for this ?I need it now …
Thanks to help me please.
Krikri
I just wanted to post this somewhere and this seems as good a place as any. I just came across an issue while working with ZendAMF and PHP that is kind of odd. I have a class that uses a constant named “NAMESPACE” for registering an namespace with DOMXpath. My remote object was failing with “NetConnection.Call.Failed” and I track the issue down to this constant. I changed it to NAME_SPACE and all is well. In my opinion this is strange behavior since I am not registering a namespace with ZendAMF and this is a perfectly legitimate construct in PHP but never the less there it is.