My ArrayCollection class

<?php
class ArrayCollection extends ArrayObject
{
        var $_explicitType = "flex.messaging.io.ArrayCollection";
       
//http://weierophinney.net/matthew/archives/131-Overloading-arrays-in-PHP-5.2.0.html
        public function __construct($config = array())
        {
                // ... some setup
        
        
                // Allow accessing properties as either array keys or object 
properties:
                parent::__construct(array(), ArrayObject::ARRAY_AS_PROPS);
        }
}
?>

When you have a ArrayCollection in Flex then you must create a
ArrayCollection in PHP. This ArrayCollection extends Arrray, so is
also a Array in PHP... Extending a ArrayObject work may be only in PHP
5.2 and +.

$this->entryData= new ArrayCollection();

$customObject= new CustomObject();
$customObject->text ="texte1";

$this->entryData[] = $customObject;

Send it to FLex and he will receive a ArrayCollection!




--- In [EMAIL PROTECTED], Kevin <[EMAIL PROTECTED]> wrote:
>
> I am interested in your fix. I think it may actually be easier than  
> my approach of having to cast the Array each time it comes back to Flex.
> 
> How do you create the initial Array collection in PHP?
> 
> $myArray = new ArrayCollection();
> $myArray->source = array();
> 
> Or is there a different way?
> 
> - Kevin
> 
> 
> 
> 
> On Mar 22, 2007, at 10:12 AM, thuijzer wrote:
> 
> > Finaly I found a solution for my problem.
> > I created this class in PHP:
> >
> > class ArrayCollection
> > {
> > var $_explicitType;
> > var $source;
> >
> > function ArrayCollection()
> > {
> > $this->_explicitType = "flex.messaging.io.ArrayCollection";
> > $this->source = array();
> > }
> > }
> >
> > When I use this in places where I need an ArrayCollection, Flex
> > recognizes this Class as an ArrayCollection :)
> >
> > - Thomas
> >
> > --- In [EMAIL PROTECTED], Thomas Huijzer <thuijzer@>  
> > wrote:
> > >
> > > Hi All,
> > >
> > > With AMFPHP 1.9 I am trying to return an Object containing some vars
> > and an ArrayCollection. Inside this ArrayCollection there are other
> > Objects. But I can't get this to work in Flex.
> > > For example:
> > > ----------------
> > > Flex class
> > > ----------------
> > > package com.app.classes
> > > {
> > > import mx.collections.ArrayCollection;
> > >
> > > [RemoteClass (alias="com.app.classes.RemoteClass")]
> > > public class MyClass
> > > {
> > > public var id: Number;
> > > public var list: ArrayCollection;
> > > }
> > > }
> > >
> > > package com.app.classes
> > > {
> > > [RemoteClass (alias="com.app.classes.RemoteClassObj")]
> > > public class MyClassObj
> > > {
> > > public var id: Number;
> > > public var name: String;
> > > }
> > > }
> > > ----------------
> > > PHP class
> > > ----------------
> > > class MyClass
> > > {
> > > var $id;
> > > var $list;
> > > }
> > > class MyClassObj
> > > {
> > > var $id;
> > > var $name;
> > > }
> > > function getData()
> > > {
> > > $data = new MyClass;
> > > $data->id = 1;
> > > $data->list = array();
> > > $data->list[0] = new MyClassObj;
> > > $data->list[0]->id = 2;
> > > $data->list[0]->name = "myName";
> > > return $data;
> > > }
> > >
> > > When I return this to Flex, the MyClass is filled ok. By the list
> > coercion fails.
> > > Any idea to solve this problem?
> > > Thank you.
> > >
> > >
> > > ---------------------------------
> > > Need Mail bonding?
> > > Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
> > >
> >
> >
> >
>


Reply via email to