CakePHP AMF /w Flex
After several hours of tests and deploys, I’ve managed to figure out a step-by-step guide to connect cakePHP to Flex3 through a AMF gateway. Please follow the steps closely, and if you have any questions, feel free to leave me a message. Good luck!
Update [May 20th, 2009] : This step-by-step guide is based on tools & tutorials made by Daniel from www.carrotplant.com
- Download flex example: http://carrotplant.com/en/blog/cpamf-flex-example
- Download php example: http://carrotplant.com/en/blog/cpamf-php-example
- Download CakePHP: http://cakephp.org
- Extract CakePHP in a folder ( lets say path_to_your_cakephp_folder )
- Edit hosts file ( /etc/hosts or C:\WINDOWS\system32\drivers\etc in most cases )
1127.0.0.1 amf.local
- Edit httpd.conf ( Apache configuration file )
1
2
3
4
5
6
7
8
9
10
11<VirtualHost *:80>
DocumentRoot C:/path_to_your_cakephp_folder/app/webroot
ServerName amf.local
<Directory "C:/path_to_your_cakephp_folder/app/webroot">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost> - Setup Security.Salt in app/config/core.php and database settings in app/config/databases.php
- Execute cpamf.sql from cpamf-php-example
- Copy from cpamf-php-example into your path_to_your_cakephp_folder folder:
- app/controllers/users_controller.php
- app/models/user.php
- app/plugins/cpamf/*
- Modify app/plugins/cpamf/vendors/amfphp/core/cakeamf/util/CakeMethodTable.php at line 74 with following:
1
2
3$className = str_replace('\', '/', $className);
$className = substr($className, strrpos($className, '/') + 1);
$sourcePath = $servicePath . Inflector::underscore( $className ) . ".php"; - Access http://amf.local/cpamf/browser and set path of gateway to http://amf.local/cpamf/gateway (without .php at end)
- Create folder app/webroot/flex, and create a Flex 3 Project called amf.local with Flash Develop
- Download the latest version of Mate AS3 Flex Framework from http://code.google.com/p/mate-framework/ (eg.: Mate_08_7.swc)
- Put the Mate SWC file into the LIB folder of your Flex project ( app/webroot/flex/lib )
- Put content of cpamf-flex-example/src into the SRC folder of your Flex project ( app/webroot/flex/src )
- Put services-config.xml into the root of project ( app/webroot/flex )
- Edit services-config.xml at line 21, to point to the right gateway
1
2
3<endpoint
uri="http://amf.local/cpamf/gateway"
class="flex.messaging.endpoints.AMFEndpoint" /> - Put the whole code of cpamf_test.mxml into Main.mxml, and keep cpamf_test.mxml for future uses
- Set properties for project ( right click on the project name, and then click on Properties )
- Compiler Options » Additional Compiler Options » SET : -services=services-config.xml
- Compiler Options » SWC Include Libraries » SET : lib/
- Compiler Options » SWC Libraries » SET : lib/
- Test/Build the project and then you can access your swf at http://amf.local/flex/bin/amflocal.swf
- Enjoy!