CakePHP + AMFPHP + Flex
CakePHP Code
In your Model file (my example is Time.php, it's a model that stores times which is part of a project management application I have) you will need to add a function to gather data just like data is being gathered in Mike Potter's example.
The important part here is the mysql_fetch_object() PHP function. It's required to return objects to Flex.
Before I go into the actual code, you should familiarize yourself with cakeamfphp or at least download and put the files in the proper locations first. You can get cakeamfphp here. It will also help to skim through the bulletin boards tutorial here.
This code goes into your Model
function justTime() {
$Query = "SELECT * from Times";
$Result = mysql_query( $Query );
while ($row = mysql_fetch_object($Result)) {
$ArrayOfTimes[] = $row;
}
return( $ArrayOfTimes );
}
The above code allows me to use $this->Time->justTime(); in my times controller. If I were to set a variable in the view so I could print the array, I could like so: $this->set('justTime', $this->Time->justTime());
Running a print_r() on that will return a much more simple array than what you normally would see in CakePHP. It also doesn't include any associated models, etc. You know it's correct when it displays an array like this: [0] => stdClass Object.
This code goes into your Controller (it's very similar to the bulletin board example)
function TimesController() {
$this->methodTable = array(
"getTimes" => array(
"description" => "Read data from DB and pass back recordset",
"access" => "remote"),
);
parent::__construct();
}
function getTimes()
{
$this->autoRender = false;
$this->constructClasses();
return $this->Time->justTime();
}
That's all you need actually to read the data. Storing data is something for another tutorial. Provided that you have cakeamfphp in the proper folders, you should be good to move on to your Flex code.