The Bulletin Board with CakeAMFPHP
April 11, 2006
this content element requires the Flash 7.0 player. You can download it here
This is an example of how to use CakePHP and AMFPHP, through the CakeAMFPHP package. In particular, this example uses the cakeMySqlAdapter.php to return a record set. If you have setup AMFPHP before you have most likely seen the fine amfphp tutorial by Jesse Stratford and Patrick Mineault. Using CakePHP takes a lot of headaches out of the database stuff and also allows you to mix html and flash seamlessly. In addition, the example includes the use of the nice UFO.js lib along with a CakeAMFPHP helper.
In 3 parts:
- Part 1: Getting Setup
- Part 2: The Cake Code
- Part 3: The AS Code
Part 1: Getting Setup:
- Get CakePHP 0.10 Final
- Get AMFPHP 1.2.3
- Get CakeAMFPHP 0.4.0
- Get Unobtrusive Flash Objects (UFO) v3.0
1. Create a directory in your webroot, name it amfBB, and unpack cake_0.10.9.2378_final into it. We should have the following structure, /var/www/amfBB/
2. Unpack amfphp-1.2.3. /var/www/amfBB/app/vendors/amfphp

Now we need to move some files around
move /var/www/amfBB/app/vendors/cakeamfphp-pkg/cakeamfphp.php to /var/www/amfBB/app/views/helpers/ move /var/www/amfBB/app/vendors/cakeamfphp-pkg/cake_gateway.php to /var/www/amfBB/app/webroot/ move /var/www/amfBB/app/vendors/cakeamfphp-pkg/cakeMySqlAdapter.php to /var/www/amfBB/app/vendors/amfphp/amf-core/adapters/ move /var/www/amfBB/app/vendors/cakeamfphp-pkg/cakeamfphp/ to /var/www/amfBB/app/vendors/cakeamfphp
4. Finally, we download and add the ufo.js to /var/www/cake/amfBB/app/webroot/js/
The Final Structure inside /var/www/amfBB should look something like this. Also very impt, you should make the tmp directory read and writable.
-app --controllers --models --tmp --vendors ---amfphp ----amf-core -----adapters ------CakeMySqlAdapter.php ---cakeamfphp --views ---helpers ----cakeamfphp.php helper for the UFO.js --webroot ---cake_gateway.php ---js ----ufo.js -cake
Overview
With everything setup we can begin to understand whats going on. Basically, we are using a modified gateway specifically designed to work with CakePHP. The cake_gateway does the things normally found in Cake's bootstrap and dispatcher. With the connection made we can let amfphp do its magic, almost. Remember the cakeMySqlAdapter.php, well that makes it possible to use AMFPHP recordsets with CakePHP.
Now we should setup the database. First, rename the /var/www/amfBB/app/config/database.php.default to database.php. Then add you connection details.
Below you can find the tables for this example. Just two simple ones.
CREATE TABLE `bulletin_boards` ( `id` int(10) NOT NULL auto_increment, `user_id` int(10) default NULL, `email` varchar(100) NOT NULL default '', `url` varchar(100) default NULL, `message` text NOT NULL, `created` datetime NOT NULL default '0000-00-00 00:00:00', `modified` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`) ) TYPE=MyISAM; CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `name` varchar(50) NOT NULL default '', `created` datetime NOT NULL default '0000-00-00 00:00:00', `modified` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`) ) TYPE=MyISAM;
- Part 2: The Cake Code
- Part 3: The AS Code
