SWX meet my recordset :)
I've played around with AMFPHP at some point, but found it just too much of a hassle to work with, so I wrote my own data services to get recordsets from a database. It started with playing a bit with the Sephiroth's Serializer and kinda started leading it's own life. Since then, i've always meant to share it, but it was never quite finished (it isn't now really either, but it works). But since Aral's presentation at LFPUG about SWX, i got a little excited, since i could keep using the backend but, but use a set of interfaces to talk to Flash now. Not just serialized data, or XML, but also directly by loading a swf (very handy for getting data into Flash Lite apps without parsing for example). Mike told me I should blog about it, so here I am.. typing away. I hope you'll find it useful.
Since it's already quite late, I'll have to keep you in suspense in regards to the sourcefiles for this (no AS files). What I will do today is share with you what the back-end testing environment looks like.
.../php/gateway.php?displayServices is the default serviceManager instance with it's methods displayed (all it does at the moment is grabbing some of the posts of this blog from the database). To test whether or not your backend is working, you can run this and view the output (select from the 5 options to have your preferred way to view content). For testing purposes, the 'raw data' option will show you the structure of the content returned. My data handling classes have paging built in (inspired by Guy Bowden - CTO at Holler the time -, but completely rebuilt from scratch since I've left some year and a half ago) and some other features I find quite handy when loading content. The serviceclass itself is similar to other service classes and I use it mainly to set up SQL queries, but it can be used for other purposed, as long as the methods within it return an array. (I'm looking into JSON at the moment).
-
<?php
-
include("core/OutputRenderer.php");
-
include("core/Serializer.php");
-
include("core/Gateway.php");
-
include('config/swx_config.php');
-
include("config/Connection.php");
-
include("core/QueryManager.php");
-
include("services/ServiceManager.php");
-
include('core/SwfCompiler.php');
-
-
$dbconn = new Connection();
-
$gateway = new Gateway($_REQUEST);
-
$gateway->generateOutput($_REQUEST['output']);
-
$dbconn->close();
-
?>
-
<?php
-
class ServiceManager extends QueryManager
-
{
-
function ServiceManager($page, $perpage, $args)
-
{
-
$this->setParameters($page, $perpage, $args);
-
}
-
function getPosts()
-
{
-
return $this->getResult("SELECT ID, post_title, post_content FROM wp_posts ORDER BY ID DESC");
-
}
-
function getPostByID()
-
{
-
return $this->getResult("SELECT ID, post_title, post_content FROM wp_posts WHERE ID='#0#'");
-
}
-
}
-
?>
anyway.. I'm sure you get the gist.
The php files (uncommented.. I need to really change my ways, sorry) are available for download here
And last but not least, I'd like to send my gratitude to Aral, Mike, LFPUG, Sephiroth & Guy.
TBC.

May 8th, 2007 at 15:10
It seems the swx conversion doesn’t work on this particular server (will look into this later)
May 21st, 2007 at 11:03
update:
it does work!
check out here: http://www.zinkhann.co.uk/flashphp/flash/swxtest.html