Flex 和 Zend_AMF:如何将 Flex arrayCollection 从 Flex 导入 PHP? [英] Flex and Zend_AMF: How do I get a Flex arrayCollection from Flex into PHP?

查看:27
本文介绍了Flex 和 Zend_AMF:如何将 Flex arrayCollection 从 Flex 导入 PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在 Flex 中有一个 arrayCollection,我想将它发送到 PHP (Zend_AMF).根据 Zend_AMF wiki,直接发送一个 arrayCollection 将强制 Zend_AMF 将 arrayCollection 转换为一个不好的对象.我宁愿拥有一系列我的模型.

I currently have an arrayCollection in Flex and I want to sent it to PHP (Zend_AMF). According to the Zend_AMF wiki, sending an arrayCollection over directly will force Zend_AMF to cast the arrayCollection as an object which is no good. I'd rather have an array of my models.

我认为最好的方法是将 arrayCollection 转换为 flex 中的数组,然后将其发送过去.这是真的吗,如果是这样,我将如何在 Flex 3 中做到这一点?

I assume the best way would be to convert the arrayCollection to an array in flex and then send it over. Is this true, and if so how would I do that in Flex 3?

如果您有更好的建议,也将不胜感激.

If you have a better recommendation, that would be appreciated as well.

感谢您的关注!

推荐答案

其实可以在 PHP 端创建一个 ArrayCollection 类型,直接通过 AMF 发送原生的 ArrayCollection 对象.

Actually, you can create an ArrayCollection type on the PHP side and send native ArrayCollection objects directly over AMF.

这是我有一些有效的 php 代码.将其保存在一个名为

Here is some php code I have that works. Save this in a file called

ArrayCollection.php

ArrayCollection.php

<?php
class ArrayCollection {
    public function getASClassName()
    {
        return 'flex.messaging.io.ArrayCollection';
    }

    var $source = array();

    function ArrayCollection()
    { 
        $this->source = array(); 
    }
}

要在 php 端使用它,请在您的 php 项目中包含 ArrayCollection.php,调用它的语法如下所示:

To use this on the php side include the ArrayCollection.php in your php project and the syntax to call it looks something like this:

$myArrayCollection = new ArrayCollection(); 

如果你想访问组成 ArrayCollection 的数组,你可以这样做

and if you want to access the array that composes the ArrayCollection you can do this

$someArray = $myArrayCollection->source;

在 Flex 端,您可以通过 Zend AMF 将数组集合直接传递到服务器.在我的一个项目中,我有许多包含 ArrayCollections 的值对象,它们在 PHP 端工作得很好.这样就可以了.

On the Flex side you can pass Array Collections directly to the server over Zend AMF. In one of my projects I have many value objects that have ArrayCollections in them and they work just fine on the PHP side. So it can be done.

如果你绝对不能让 ArrayCollection 在 PHP 中工作,你可以在 Actionscript 中访问数组作为 ArrayCollection 的源"属性.actionscript 中的代码如下所示:

If you absolutely can't get the ArrayCollection working in PHP you can just access the array as the "source" property of the ArrayCollection in Actionscript. The code looks something like this in actionscript:

import mx.collections.ArrayCollection;

public var myAC:ArrayCollection = new ArrayCollection();

public var myArray:Array = new Array();

// populate your ArrayCollection with data...

myArray = myAC.source;

myArray 现在将是 ArrayCollection myAC 中对象的数组.

myArray will now be an Array of the objects in the ArrayCollection myAC.

希望这会有所帮助.如果您有其他问题和/或有代码示例,请告诉我.

Hope this helps. If you have further questions and/or have a code sample let me know.

我也花了一些时间才弄明白.

It took me a bit to figure this one out too.

这篇关于Flex 和 Zend_AMF:如何将 Flex arrayCollection 从 Flex 导入 PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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