CakePHP + AMFPHP + Flex


Introduction
CakePHP Code
Flex Code

Working Demo
Download Source


Flex Code

Basically the Flex code is the same as Mike Potter's tutorial on using AMFPHP and Flex.

Follow it and you should be set, you can skip ahead to the third page really because the other part is about the PHP code which you already have.

I am actually not going to duplicate what he has written because it really is the same. The important thing to note is that you'll be using AMF0 and you will need the actionscript file that he illustrates in his tutorial. That originally came from Tweenpix.

NOTE that since writing these notes, I've found a way to use AMF3 encoding and AMFPHP 1.9. Thanks to gwoo at rd11.com for his work with integrating AMFPHP 1.9 into CakePHP. I would be completely lost otherwise and would have to run AMFPHP outside of CakePHP and that would just be messy. His efforts are the entire reason we're at this point of "seamless" integration into Cake if you will.
That remoting connection actionscript file (from Tweenpix) can then simply be changed to use AMF3 by changing "AMF0" to AMF3" or leaving it blank as the default encoding value is AMF3. So it's like an upgrade.

The other important part to illustrate is where there will be ever so slight changes...

public function initApplication()
{
gateway = new RemotingConnection( "http://localhost/flex/php/gateway.php" );
gateway.call( "sample.getUsers", new Responder(onResult, onFault));
}

You'll want to replace that function with information that relates to what you setup in your cake code.

Mine looks like this
public function initApplication() : void
{
gateway = new RemotingConnection( "http://127.0.0.1/appdirectory/cake_gateway.php" );
gateway.call( "TimesController.getTimes", new Responder(onResult, onFault));
}

Note that you're calling "TimesController.getTimes" ... "TimesController" was setup as a function to define your method table in your cake controller and "getTimes" is the actual function in your method table (again you can have many). Your gateway file will also be inside your webroot directory and should be called cake_gateway.php as per the cakeamfphp package.

Hopefully these notes filled in the gaps. It's really just some minor differences in how data is prepared/passed, but unfortunately I couldn't find anyone out there who knew what those differences were...but now we know.

What next?
Perhaps modifying the bake.php script to output mxml files for views in CakePHP applications? Perhaps. Well what about compiling them? Ahh...didn't I just read about some nifty server extension that just came out (in alpha or beta or whatever) that will let the server compile the mxml so you can just go to a web address of http://www.site.com/file.mxml ?? There are many possiblities with Cake and Flex. I personally believe it to be a very good way of creating rich internet applications.