CAKEPHP + AMFPHP using AS3

Posted 471 days ago

I've been using the PHP framework CakePHP quite a bit recently, and wanted to integrate the Open Source Flash remoting solution AMFPHP into my workflow, so I could keep all my related functions in the relevant Cake controller classes.

CakeAMFPHP does this nicely. It's just a matter of dropping the files in your vendors directory, dropping the cake gateway in the webroot, and changing your path settings if you haven't gone with the default Cake directory structure.

The example code demonstrating how to include this in your controller classes is pretty straightforward:

// required for amfphp classes
function myController()
{
	$this->methodTable = array(
		"amfCreate" => array(
			"description" => "Inserts data from flash into DB",
			"access" => "remote"
         ),
		"amfRead" => array(
			"description" => "Read data from DB and pass back recordset",
			"access" => "remote",
		)
	);
	parent::__construct();
}

function amfCreate($params)
{
	$this->autoRender = false;//make sure cake doesnt render a view - it's an amf method
	$this->constructClasses();//this will create the models needed for this method
	return $params['arg1'] . " and " . $params['arg2'];
}

However because I'm switching to AS3 I wasn't initially sure what modifications might be required (using the amfBB example as a reference), and it turns out things are much more straightforward.

A little searching turned up Oscar Trelles' AS3 Remoting example post, in which he demonstrates a simple wrapper class which sets the appropriate AMF version for AMFPHP. I'll repeat it here merely for the purposes of testing out that Google code prettifier :)

package
{
	import flash.net.NetConnection;
	import flash.net.ObjectEncoding;

	public class RemotingService extends NetConnection
	{

		function RemotingService(url:String)
		{
			// Set AMF version for AMFPHP
			objectEncoding = ObjectEncoding.AMF0;
			// Connect to gateway
			connect(url);
		}
	}
}

SWX at Play

flash
Posted 474 days ago

Aral Balkan popped up from Brighton last Wednesday to deliver an enthusiastic presentation of his new take on data exchange for Flash at last month's London Flash Platform User Group (LFPUG) meeting. (No I also don't think the acronym has improved much since it was LMMUG!)

Why roll your own!?

Posted 501 days ago

I finally decided to ditch Wordpress, roll up my sleeves, and roll my own weblog system. I used to think rolling-your-own might be a bit of an inefficient, egotistical, timewaster, but now I'm not so sure.

A pale blue dot

Posted 661 days ago

Imagine looking back towards Earth from 4 billion miles.

Kurt Vonnegut says this is the end of the world

Posted 670 days ago

I ask him whether he worries that cigarettes are killing him. "Oh, yes," he answers, in what is clearly a set-piece gag.