View Full Version : RemoteObject and AMFPHP
I was wondering if it was possible to send an object to a php class though AMFPHP ?
I have tried and for some reason I can't find a way... I can send without any problem my variables like username and password, and catch it in my php class. As soon as I try passing an object it fails...
var o:Object = new Object();
o.username = 'test';
o.password = 'test';
in my php class:
function login($o)
{
if($o == NULL) return NULL;
$sql = INSERT INTO users (username, password) VALUES ($o->username, $o->password);
...
}
It does insert something, but it a blank... Anyone knows how I can catch my username and password ?
Peter Cowling
11-09-2008, 06:30 PM
Hi,
I think you need to send the values as part of a value object if you want to work this way.
do you mean that I can't send an object, I can only send variables ?
drkstr
11-10-2008, 01:34 AM
A dynamic Object in Flash comes across as an associative array in PHP.
$o['username']
$o['password']
Best Regards,
~Aaron
Peter Cowling
11-10-2008, 01:47 AM
Hi,
You can map objects, so that AMFPHPs, AMFDeserializer understands how to allocate specific parts of an object to its PHP counterpart. To do this, you have build objects like this:
Actionscript
package path.to.asClasses
{
[RemoteClass(alias="path.to.MyAliasClass")]
public class MyASClass
{
public var id:uint;
public var name:String;
}
}
PHP
<?php
class MyAliasClass
{
var $_explicitType = "path.to.MyAliasClass";
var $id;
var $name;
public function MyAliasClass( ){}
}
?>
However, as per here (http://www.5etdemi.com/blog/archives/2007/01/why-you-shouldnt-use-class-mapping-and-vos-in-amfphp/), maybe that is not the best way. In that article, it states that:
"As for incoming class mapping, remember that if amfphp doesn't find the class to be mapped in the services/vo folder, it will simply deserialize the object as though it were untyped, that is, as an associative array. "
So that should mean that you can treat the object as an associative array in your php.
EDIT: As Aaron has commented whilst I typed this out...
creynders
11-10-2008, 12:26 PM
If you do however want to use the object mapping, then it's required that you place the VO classes in exactly the same path structure inside your vo directory, as you defined in the alias. Meaning that if you defined the alias as
[RemoteClass(alias="com.somedomain.MyAliasClass")]
then the file needs to be in directory structure
{vo directory}
__|-com
____|-somedomain
______|-MyAliasClass.php
thanks, I will use the associative array
thank you for your help
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.