AMF类映射不起作用 [英] AMF class mapping not working

查看:110
本文介绍了AMF类映射不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Flex 4.5和Zend_AMF作为我的AMF端点来构建应用程序。

I am building an application using Flex 4.5 and Zend_AMF as my AMF endpoint.

我想将PHP中名为CRequest的类映射为Request中的类

I would like to map a class called CRequest in PHP to a class called Request in Flex.

这是我的php类:

<?php
namespace app\web;

class CRequest{
   public $_explicitType = 'com.site.remote.Request';

   public $stuff1;

   public $stuff2;

}

这是动作类:com.site.remote。 Request

This is the actionscript class: com.site.remote.Request

package com.dreamatique.remoting
{
    [Bindable]
    [RemoteClass(alias="com.site.remote.Request")]
    public class Request
    {

        public var stuff1:String;

        public var stuff2:String;

        public function Request()
        {
        }
    }
}

作为测试,无论请求如何,我都使端点从PHP端返回了 CRequest 的实例。

As a test, I have made the endpoint return an instance of CRequest from the PHP side, no matter what the request.

然后我要像这样进行远程对象调用:

I am then making a remote object call like this:

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();

public static function result(event:ResultEvent):void{

    trace(event.result);
    trace(Class(getDefinitionByName(getQualifiedClassName(event.result))));
    Alert.show(event.result.toString());

}

问题是返回的结果为 ObjectProxy 而不是 Request 。我在做什么错?

The problem is that the result comes back typed as ObjectProxy and not Request. What am I doing wrong?

推荐答案

请确保您在代码库中的某个位置至少有一个对该类的引用。

Ensure that you have at least one reference to the class somewhere in your codebase.

这是一个常见的陷阱,尤其是在第一次开发远程调用时,以及在您实际在任何地方的任何代码中使用过该类型之前。

This is a common trap, especially when first developing a remote call, and before you've actually consumed the type in any code anywhere.

如果未引用该类,则不会在其中编译该类,因此不会进行注册。

If the class is not referenced, it's not compiled in, and therefore, doesn't get registered.

通常,在早期开发期间,我会最终创建一个 StaticLinker 类:

Often, during early development, I'll end up creating a StaticLinker class:

public class StaticLinks
{
    private var request:Request;
}

然后在我的应用程序中引用它:

Then reference this in my application:

<s:Script>
   var linker:StaticLinks;
</s:Script>

BTW-您先前的假设是正确的:如果您将课程注释为 [RemoteObject] ,则无需调用 registerClass()

BTW - you're correct in your earlier assumption: If you have annotated the class as a [RemoteObject], you're not required to call registerClass().

这篇关于AMF类映射不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆