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

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

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 [...]

8 Responses to “Returning query results from CodeIgniter models using AMFPHP, CI and FLASH”

  1. Ronin Says:

    Yes, I know I need to get a code plugin for the blog so I can actually post my code as text into my posts. So please forgive me (teh n00b) for posting the code as images.

  2. chinna Says:

    Good to know the tip on how to pass the values

  3. AMF Says:

    good info

  4. andreas Says:

    hi - good hints for a starting point. is there also a way of using the codeigniter libraries?

    or is it also possible to go he other way -> integrate amfphp into codeigniter (like the ci xmlrpc class)? anybody tried that?

  5. Ronin Says:

    I’m not entirely sure but i’d guess that it is possible. I’m fairly new to Code Igniter and post as I go along :)

    If you find anything any where else please link to it.

    Cheers.

  6. KJ Says:

    I found this excellent post that gives you an idea on how to convert the AS2 code shown here into a working AS3 equivalent. Very nice.

  7. Jacacado Says:

    Thanks for the info. One little thing I wanted to mention (and it’s obvious). AMFPHP creates its own method table with PHP5, but you still need to put the actual methods in your services file. I made the mistake of thinking that I could call methods in my CI model directly from flash. The services php file still needs the function to talk with the CI model.

  8. Ronin Says:

    Hey Jacacado, thanks for the input. Glad you found this article helpful.

Leave a Reply