Hello. I have a new blog.

I've moved this blog to the following URL Kerkness.ca. Thank you for visiting, please update your bookmarks.

Sunday, February 17, 2008

Flex / JSON / PHP Example Application

While trying to teach myself how to best use PHP and Flex together I build the following example application. Source code and details on how the application works are included.

The example application uses JSON (JavaScript Object Notation) to facilitate a smooth and simple way of providing PHP Arrays that can be used by a Flex Application. A more complete HowTo is included in the application.

Click here to launch the application
(right click to view source)

Requirements

This application requires a php class called json.php which encodes a PHP array and the corelib libraries available from Adobe Labs used to decode the array in Flex. You'll also need a mysql database with a single table called 'people' with the fields 'firstname','lastname' and 'category'.

To install the corelib libraries I used a post at Mike Chambers blog.
The json.php class originally comes from M. Migurski.

MXML Summary

Right click the example application to view the MXML source

  • FlexPhp.mxml : Main Application file. Contains a navigation tab and loads the components PhpDataGrid.mxml and PhpForm.mxml
  • PhpDataGrid.mxml : Contains a simple DataGrid and ActionScript for calling read.php
  • PhpForm.mxml : Contains a simple Flex form and ActionScript for calling write.php
Description of PHP Files

read.php : File queries the database and returns a JSON encoded array to the Flex application.
write.php : File accepts data posted from Flex form, updates the database and sends a JSON encoded response back to the flex application.
json.php : Class file used to encode PHP arrays into a JSON formatted string.
mysql.php : Class file for accessing and updating the database.
conf.php : Simple configuration file for keeping database access information and debugging.


No comments:

Post a Comment

Thank you for the comments.