0

从 Zend AMF 收到 Flex 对象 (ArrayCollection) 后,我无法访问它。发送的原始类型是 PHP 关联数组,它简单地返回,如

return $this->sections['initial_setup'];

PHP 变量视图:

变量视图中的节数组

在 Charles AMF RPC 选项卡中发送的所需结果如下所示:

Charles 代理 AMF RPC 视图

但是当我将 Flex 中的数据作为对象(或 String[] - 没关系)接收时,我无法访问此类代码中的属性值

    var result:Object = event.result;
    if (result['database'] == 'yes' && result['admin'] == 'yes')
        // continue branch ...

我在 if-line 上遇到异常:

    Error: Unknown Property: 'database'.
        at mx.collections::ListCollectionView ...

最后,我可以在 Eclipse 变量视图中看到 ResultEvent 实例带有长度为 0 的 ArrayCollection 类型的结果,并且接收到的值通过 D 图标可见(我找不到 D 装饰的含义):

结果事件变量

但是为什么我仍然无法访问它们,我应该怎么做才能使用它们?

我试图更改 Array 或 ArrayCollection 的类型而不是 Object。还有一个讨论类似问题的线程,但在尝试之后,它也无济于事。

任何帮助将不胜感激:o)

编辑 1: 这是 FB 为 ConfigurationService 生成的超类构造函数的代码:

    // Constructor
public function _Super_ConfigurationService()
{
    // initialize service control
    _serviceControl = new mx.rpc.remoting.RemoteObject();

    // initialize RemoteClass alias for all entities returned by functions of this service

    var operations:Object = new Object();
    var operation:mx.rpc.remoting.Operation;

    operation = new mx.rpc.remoting.Operation(null, "readSettings");
     operation.resultType = Object;
    operations["readSettings"] = operation;
    operation = new mx.rpc.remoting.Operation(null, "writeSettings");
    operations["writeSettings"] = operation;
    operation = new mx.rpc.remoting.Operation(null, "readDBSettings");
     operation.resultType = valueObjects.ConnectionParams;
    operations["readDBSettings"] = operation;
    operation = new mx.rpc.remoting.Operation(null, "writeDBSettings");
    operations["writeDBSettings"] = operation;
    operation = new mx.rpc.remoting.Operation(null, "readInitSetupCompletion");
     operation.resultType = Object;
    operations["readInitSetupCompletion"] = operation;
    operation = new mx.rpc.remoting.Operation(null, "writeInitSetupCompletion");
    operations["writeInitSetupCompletion"] = operation;

    _serviceControl.operations = operations;
    _serviceControl.convertResultHandler = com.adobe.serializers.utility.TypeUtility.convertResultHandler;
    _serviceControl.source = "ConfigurationService";
    _serviceControl.endpoint = "gateway.php";


     preInitializeService();
     model_internal::initialize();
}
4

1 回答 1

1

所以这里发生的事情是,作为 ArrayCollection 源的 Array 充当具有这两个属性的通用对象。可能生成的代码假设您将始终返回多个对象,并且当您的数据不满足 Adob​​e 工程师对此的假设时遇到问题。我不喜欢生成代码的原因之一:-)。

查看这些资源,了解如何“自己动手”。

  1. 关于远程的思考
  2. AMFPHP 到 Flex 对象关系映射
  3. 实现 PHP 服务

我认为最后一个 (3) 最接近您在 PHP 中可能拥有的内容。如果您确实决定使用 VO,您可能只需将 $explicitType 添加到您的行返回中,而无需在 PHP 方面进行太多其他更改。如果你走这条路,你可能需要重新生成你的服务,因为我怀疑生成的代码会有所不同。好消息是 Adob​​e 工程师可能确实想到了您有明确类型但只有一条记录的情况。

另一个解决方法是检查您的 AC 是否有一个不为空的零长度源,并在其边缘查找您的属性。

于 2012-06-23T02:52:03.257 回答