Yesterday, I succeeded in sending typed objects from a PHP application to a flex front-end using Zend_AMF as per this question.
The problem I am facing now is that I would like to send a typed object from flex to PHP and on the PHP side, be able to recieve it as a typed object instead of stdClass
.
Here is the class in flex:
package com.mysite
{
[Bindable]
[RemoteClass(alias="CTest")]
public class CTest
{
public var stuff1:String;
public var stuff2:String;
public function CTest()
{
}
}
}
And this is the corresponding class in PHP:
<?php
namespace modules\testing;
class CTest{
var $_explicitType = 'CTest';
var $stuff1;
var $stuff2;
}
In flex, I am sending the object like so:
var remoteObject:RemoteObject = new RemoteObject();
remoteObject.endpoint = "http://localhost/to/my/amf/endpoint";
remoteObject.showBusyCursor = true;
remoteObject.source = 'testing';
var op:AbstractOperation = remoteObject.getOperation(null);
op.addEventListener(ResultEvent.RESULT, result);
op.send( new CTest());
On the PHP side, the object is retrieved into a variable called $parameters
. I then use print_r on it to write the result to a file:
$z = print_r($parameters, true);
$s = fopen('D:\test.txt', 'w+');
fwrite($s, $z);
fclose($s);
And as can be seen, the result comes back untyped and is a stdClass
object:]
Array
(
[0] => stdClass Object
(
[stuff1] =>
[stuff2] =>
)
)
After some testing, I removed the namespace from the PHP object and moved it into the global namespace. This seems to have resolved the issue. I have tried setting RemoteClass
to \modules\testing\CTest
and also modules.testing.CTest
. $_eplicitType
was then set to the same value for both tests.
The result is that when I use modules.testing.CTest
, this is the classname that Zend_AMF sees. If I use namespace notation, Zend_AMF sees modulestestingCTest
, as all the slashes get stripped out.
But how can I get this working with php namespaces?