CAKEPHP + AMFPHP using AS3
Posted 497 days agoI'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);
}
}
}