Archive for the ‘AMFPHP’ Category

Returning query results from CodeIgniter models using AMFPHP, CI and FLASH

Friday, July 13th, 2007

The previous example on Flash, AMFPHP and CodeIgniter basically demonstrates how to return a simple string value to your flash movie. It’s a good idea to read that before doing this.

The following example details how to return a recordset from your database query in your CodeIgniter model. Assuming you got the setup working on the first example, the following should be relatively straightforward.

Today I’ve managed to return a recordset from the database and display entries from that recordset.

I’ll just post the code and go through it line by line.

CodeIgniter model (listingsmodel.php)

CodeIgniter Model

AMFPHP Service Class (Press.php)

Service Code

ActionScript 2 code

Actionscript Code

The code for the Model function and the AMFPHP service class are relatively straightforward. Lines 14-20 in the Actionscript2 code show how to access the array contents.
Line 16 displays everything that is past back as one huge nested array.
Line 17 displays just the data from the records in the database
Line 18 displays the length of the data array
Line 19 displays a specific value of the specified fieldname from the specified record

You can of course modify the code to do a loop that will utilise the array contents however you like.

Useful links

AS3 FLASH REMOTING EXAMPLE
RECORDSETS
OBJECTDUMPER