|
|
Rank: Newbie Coder Groups: Member
Joined: 4/28/2008 Posts: 6 Points: 0
|
Has anyone successfully serialized private variables in PHP with private variables in Flex? Here is what I am talking about.
PHP Object
class foo{ private $_name = "";
public function getName(){return $this->_name;} public function setName($val){$this->_name = $val;} }
AS object [Bindable] [RemoteObject(alias="model.foo")] public class foo{ private var $_name:String = ""; public function get name():String{return this._name;} public function set name(val:String){this._name = val;}
}
when i make a remote service call the objects are of the correct type but the values for the attributes are blank. now if i make all the fields on the php side public and remove the _ (ie. public var $name) then the values are there.
has anyone else ran into this problem? I have used this type of approach before in ColdFusion but I on the CF object side you must specify all the fields in tags, and i think that is how it knows to match up the correct fields.
my options seem to be, make public variables on the PHP side, well i dont really want to do that. or figure out how to make this work. i should be able to have private variables on both the flex and php side.
|
|
Rank: Newbie Coder Groups: Member
Joined: 4/28/2008 Posts: 6 Points: 0
|
Another thought is create a DataTransitionObject DTO that will have all public fields for the objects that I am going to send over the wire. This has two sides though, annoying b/c i have to create another object for each one that i will be sending accross the line and i have to get and set each property in the DTO. But it would work and allow me to keep all the properties in my objects to be private. Of course there would also be the extra function call to map the data from the value objects (private variables) to the DTO's (public variables).
any thoughts?
|
|
Rank: Apprentice Coder Groups: Member
Joined: 10/2/2007 Posts: 19 Points: 0 Location: Ireland
|
spydermonkey wrote:Another thought is create a DataTransitionObject DTO that will have all public fields for the objects that I am going to send over the wire. This has two sides though, annoying b/c i have to create another object for each one that i will be sending accross the line and i have to get and set each property in the DTO. But it would work and allow me to keep all the properties in my objects to be private. Of course there would also be the extra function call to map the data from the value objects (private variables) to the DTO's (public variables).
any thoughts? I'm curious about this too! Because I couldn't find an elegant solution, I basically did the above. Wherever I had an ActionScript class Class I had a sister class called ClassPHP. Class had a function called toPHP and ClassPHP did the opposite. Basically I needed to store the x and y properties of an object in a database. Since these were inherited and use getters/setters, my remote object was receiving empty data in these fields so I had to resort to the method I described. Is there a nicer way to do this? It'd be nice to know :)
|
|
Rank: Apprentice Coder Groups: Member
Joined: 10/2/2007 Posts: 19 Points: 0 Location: Ireland
|
I tried implementing the IExternalizable interface to manually choose which properties to serialise but WeborbPHP didn't like it.
|
|
Rank: Newbie Coder Groups: Member
Joined: 3/19/2008 Posts: 7 Points: 0 Location: USA
|
I don't believe you quite understand the way PHP can overload its members. This is how I would do it in PHP5: class foo{ private $name = ""; public function __get(){return $this->name;} public function __set($val){$this->name = $val;} } $myFoo = new foo(); $myFoo->name = "My Name"; echo $myFoo->name; If there are multiple members you need to use an array. For more details check out http://us.php.net/manual/en/language.oop5.overloading.phpDisclaimer: I have not tried this technique with remote objects in Flex.
|
|
|
Guest |