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

问题描述

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

我认为最好的方法是将arrayCollection转换为flex中的一个数组,然后发送它。这是真的,如果是的话,我将如何在Flex 3中做到这一点?



如果您有更好的建议,那也是值得赞赏的。



感谢您的期待!

解决方案

其实,您可以创建在PHP端使用ArrayCollection类型,直接通过AMF发送本地的ArrayCollection对象。

这里有一些我使用的php代码。将它保存在一个名为

的文件中。

ArrayCollection.php

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

var $ source = array();

函数ArrayCollection()
{
$ this-> source = array();






使用这个在php方面包括ArrayCollection。 PHP在你的PHP项目和语法来调用它看起来像这样:

  $ myArrayCollection = new ArrayCollection(); 

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

  $ someArray = $ myArrayCollection-> source; 

在Flex方面,您可以通过Zend AMF直接将Array Collections传递给服务器。在我的其中一个项目中,我有许多具有ArrayCollections的值对象,它们在PHP方面工作得很好。所以可以这样做。



如果你绝对不能在PHP中使用ArrayCollection,你可以直接访问数组作为Actionscript中ArrayCollection的source属性。代码在actionscript中看起来像这样:

  import mx.collections.ArrayCollection; 

public var myAC:ArrayCollection = new ArrayCollection();

public var myArray:Array = new Array();

//使用数据填充ArrayCollection ...

myArray = myAC.source;

myArray现在是ArrayCollection myAC中对象的数组。 b

希望这有助于。如果你有进一步的问题和/或有一个代码示例让我知道。



我花了一点时间来解决这个问题。


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.

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.

Thanks for looking!

解决方案

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

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

ArrayCollection.php

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

    var $source = array();

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

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

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

$someArray = $myArrayCollection->source;

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.

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 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到Flex获取Flex arrayCollection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 04:03