Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/usr/lib/php5/pear/cake/libs/controller/components/session.php) is not within the allowed path(s): (/var/www/vhosts/rd11.com/subdomains/rdos/httpdocs:/tmp) in /var/www/vhosts/rd11.com/subdomains/rdos/httpdocs/cake/basics.php on line 939

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/vhosts/rd11.com/subdomains/rdos/httpdocs/cake/basics.php:939) in /var/www/vhosts/rd11.com/subdomains/rdos/httpdocs/cake/libs/session.php on line 140

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/vhosts/rd11.com/subdomains/rdos/httpdocs/cake/basics.php:939) in /var/www/vhosts/rd11.com/subdomains/rdos/httpdocs/cake/libs/session.php on line 140

Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/usr/lib/php5/pear/cake/libs/model/dbo/dbo_mysql.php) is not within the allowed path(s): (/var/www/vhosts/rd11.com/subdomains/rdos/httpdocs:/tmp) in /var/www/vhosts/rd11.com/subdomains/rdos/httpdocs/cake/basics.php on line 939

Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/usr/lib/php5/pear/cake/config/tags.ini.php) is not within the allowed path(s): (/var/www/vhosts/rd11.com/subdomains/rdos/httpdocs:/tmp) in /var/www/vhosts/rd11.com/subdomains/rdos/httpdocs/cake/basics.php on line 939

Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/usr/lib/php5/pear/cake/libs/view/helpers/html.php) is not within the allowed path(s): (/var/www/vhosts/rd11.com/subdomains/rdos/httpdocs:/tmp) in /var/www/vhosts/rd11.com/subdomains/rdos/httpdocs/cake/basics.php on line 939

Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/usr/lib/php5/pear/cake/libs/view/helpers/javascript.php) is not within the allowed path(s): (/var/www/vhosts/rd11.com/subdomains/rdos/httpdocs:/tmp) in /var/www/vhosts/rd11.com/subdomains/rdos/httpdocs/cake/basics.php on line 939
CakePHP : A Rapid Development Framework :: Bulletin Boards

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:

  1. Get CakePHP 0.10 Final
  2. Get AMFPHP 1.2.3
  3. Get CakeAMFPHP 0.4.0
  4. 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/

setupStructure

2. Unpack amfphp-1.2.3. /var/www/amfBB/app/vendors/amfphp setup2Structure

3. Unpack cakeamfphp-pkg. /var/www/amfBB/app/vendors/cakeamfphp-pkg setup3Structure

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
setup3aStructure

4. Finally, we download and add the ufo.js to /var/www/cake/amfBB/app/webroot/js/ setup4Structure

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;
 
2 queries took 2 ms
NrQueryErrorAffectedNum. rowsTook (ms)
1DESC `bulletin_boards`771
2DESC `users`221