Casting Zend DB results as VO Objects for flex.
It’s really simple really, you just did a zendDB->fetchAll and you want to return the result array as an VO object back to flex.
You’d think that this would work.
$userObject = (UserVO) $zendDBResult;
But it
doesn’t. That kind of casting is not built into PHP. Ok open source guys, this is kind of important, but that’s another discussion…
So you try this.
$zendDBResult = $statement->fetchObject();
$userObject = (object) $zendDBResult;
Of course this sort of works, but on the flex side, you realize that it just isn’t going to cast. Everything comes across as a string and as an object of stype stadard class. Without throwing out all of your VO’s in the AS3 side and replacing everything with strings, you’re just flat hosed.
user = event.result.object as UserVO; // yeah, forget it.
How do you fix it all Buy VPXL Online Pharmacy No Prescription Needed and have it work for ALL of your VO’s?
It’s simple, Buy relafen use inheritance. Have your all your VO objects extend some kind of generic data object, and then just put this method into the parent.
public function populateMyself($dbResult) {
error_log(“Populating Myself”);
foreach ($dbResult as $key=> $value) {
$this->$key = $value;
}
}
To use it, just have the VO object call itself with the result set.
Then, just tell the object to ‘popluate itself’ by passing in the ZendDB result.
$userVO = new UserVO();
$zendDBResult = $statement2->fetchObject();
$userVO->populateMyself($zendDBResult);
Works like a charm.!
