Powered By

Steps to Install and Connect to PHP in Flex using AMFPHP

Tags : | |
If you are bored of using XML to transfer data from PHP to Flex, then here is a end for your boredom. Using AMFPHP, you can convert data object in PHP to dataobject in action script so that you can use that in your flex project.

Download Source:

Here are the steps to install and integrate AMFPHP with Flex.
  1. First of all download AMFPHP, depending upon the platform and os you are using. Then unzip the downloaded file,rename it to amfphp and place it in the root folder of your web server.
  2. To make sure amfphp is working correctly, go to http:/localhost/{amfphp}/gateway.php if you are working in local or use your server name instead of localhost.
  3. If you get the success message, then go ahead or look into the documentation for additional configurations.
  4. Then create a new flex project, with server type as PHP. Enter your valid web root and base url.
  5. Create a file called service-config.xml and save in the src folder. You can get the content of this xml file from the download source package.
  6. In the main mxml file, the data object from php is received through RemoteObject class in flex as

    < mx:remoteobject id="amf" source="AMFPHPConnect.Connect" destination="amfphp" > < mx:method name="testConnection" result="onConnect(event)" > </mx:method > </mx:remoteobject >
  7. Don't forget the give the same name for remote object destination and service-config.xml destination id.
  8. Give the correct path for the gateway.php file in the channels tag.

    <channels>
    <channel-definition id="my-amfphp" class="mx.messaging.channels.AMFChannel">
    <endpoint uri="http://{webroot}/amfphp/gateway.php" class="flex.messaging.endpoints.AMFEndpoint"/>
    </channel-definition>
    </channels>
  9. Create a simple php file and place it inside the 'services' folder inside amfphp installation. Under the a folder 'AMFPHPConnect' and name the php file 'Connect.php'.
  10. So that you can give the source for the RemoteObject class as 'AMFPHPConnect.Connect'.
  11. To call a method in the php file use <method> tag as
    <mx:method name="testConnection" result="onConnect(event)" />
  12. Before compiling the project, you must intimate the compiler that you are using amfphp, by specifying the compiler argument as shown.

  13. Then the output will be something like this:


Related Posts by Categories