Legal
The views expressed in this blog are my own and do not necessarily reflect the views of Adobe Systems Incorporated.
Search
June 21, 2006
Download a Flex / PHP Framework, with Source Code
Digg This!When we were at the New York PHP Conference last week, one of the things that struck me was how hard it was to get started with Flex and PHP. You have to go to one site to download Flex Builder, then to another site to download AMFPHP, then build out your application, deploy it etc...
I thought I could help out, so I built a small framework that includes AMFPHP along with some sample files. The Flex application simply displays information from a MySQL database in a Flex application. Very simple. Here's how you, as a PHP developer, get started:
1. Download the Flex / PHP Framework .zip file.
2. Extract the .zip file in your website. The files must be put in a directory called flex_project in your web server's root directory (ie. /flex_project) (the .zip file should create the flex_project automatically, so you should just extract to the root dir.).
3. Create a database called sample, and populate it with the data from sample.mysql in the flex_project directory.
4. Modify the line $mysql = mysql_connect(...); in the file flex_project/amfphp/services/sample.php to be able to connect to your database.
5. Visit http://localhost/flex_project/amfphp/services/sample.php. (Change localhost if you haven't installed on a local machine). You should see some output.
6. Visit http://localhost/flex_project/bin/flex_project.html to see the Flex application in action. You will need Flash Player 9 for this to work properly.
To modify the backend PHP code, you'll want to change the file in flex_project/amfphp/services/sample.php
To modify the front end Flex code, you'll want to download Flex Builder, create a new Flex project with the source of it as the flex_project directory. Then, modify the flex_project/flex_project.mxml file. When you save that file, it will update the .swf file in the bin/ directory, so reloading http://localhost/flex_project/bin/flex_project.html should show you an updated application.
One thing to note that I've changed in this compared to other uses of Flex and AMFPHP. In AMFPHP, I commented out the following lines in amfphp/app/Filters.php:
$outHeader = new AMFHeader("AppendToGatewayUrl", false, "?" . ini_get('session.name') . "=" . $session_id);
$amf->addOutgoingHeader($outHeader);
I'm not too sure what that was doing, but it was calling an ActionScript function AppendToGatewayURL that was blank in my previous tutorials. Doing this removed the need to create a RemotingConnection.as file in your Flex Project. You'll notice this because the connection to gateway.php now looks like this:
gateway = new NetConnection();
gateway.objectEncoding = flash.net.ObjectEncoding.AMF0;
gateway.connect( "/flex_project/amfphp/gateway.php");
gateway.call( "sample.queryDatabase", new Responder( onResultQueryDatabase, onFault ) );
Hopefully this .zip file is helpful for PHP developers. It shouuld be relatively easy to extend this sample to include the ability to create, update and delete elements from the database. If you do that, please send me an updated .zip file to post on this site.
technorati tags:adobe, php, flex, amfphp, mysql, flash
Blogged with Flock
Comments
Just to clarify. . ....
you dont need Flex or Flex Data Services (or anything like that) to get this demo working remotely, right?
[Yes, that's right... Its just a .swf file, and you can edit the .mxml file in Notepad, then use the Flex SDK (which is free) to update the .swf file in the bin/ directory - Mike]
hi, nice example, but doesn't work on my box (xp sp2, f2b3, fp9). Details:
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.Failed
at flex_project/init()
at flex_project/___Application1_creationComplete()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/set initialized()
at mx.managers::LayoutManager/::doPhasedInstantiation()
at mx.core::UIComponent/::callLaterDispatcher2()
at mx.core::UIComponent/::callLaterDispatcher()
Can you tell me what could be wrong? (Step 5 from your tutorial shows the results form amfphp)
Thanks. br, Milan
Nice example. Thx a lot. Works fine for me, same conf as milan.
I'd like to see a Flex/PHP/Cairngorm framework with an AMF3-compatible version of AMFPHP.
How would one go about uploading a large file, say 500MB using Flex for the front end, PHP on the back end?
Works just fine as described :)
Nice Script and Frame work.
I get the same problem as Milan. All works fine when testing on my laptop's localhost server but when uploaded to two separate remote servers I get that same message:
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.Failed
Can anyone help?
Thank you for signing in, You may now comment. (Sign Out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)