Using CakeAMFPHP 0.6 w/ Cake 1.2

By ryan (morris)
This is intended as a guide for those out there who *were* using the splendid CakeAMFPHP 0.6.0 with Cake pre-1.2 and want to be able to continue using it in Cake 1.2.

If you have the means to upgrade your gateway, or if you are starting a new project in Cake 1.2, it would be best to use something like CakeAMF (+ amfext) https://trac.cakefoundation.org/amf/ or CakeSWXPHP http://blog.aboutme.be/cakeswxphp/ for your flash/flex remoting needs. I have not used either of these personally though many folks have recommended them to me.

This guide assumes you are starting with:

  • Cake 1.2 RC2 (or above will likely work)
  • CakeAMFPHP 0.6.0
  • AMFPHP 1.9

I would like to thank John David Anderson for helping me get CakeAMFPHP working in Cake 1.2!


Let us begin!


  1. Edit app/webroot/amfbrowser/config.inc.php, line 75
    • Change to App::import('Controller', null);
    • Add App::import('Controller', 'App');

  2. Edit app/webroot/cake_gateway.php, line 75
    • Change to App::import('Controller', null);
    • Add App::import('Controller', 'App');
    • Add require_once(APP.'vendors'.DS.'cakeamfphp'.DS.'amf-core'.DS.'app'.DS."CakeGateway.php");
    Before:
    Download code require CORE_PATH.'cake'.DS.'bootstrap.php';
    loadController (null);  
    vendor('cakeamfphp'.DS.'amf-core'.DS.'app'.DS."CakeGateway");    
    After:
    Download code require CORE_PATH.'cake'.DS.'bootstrap.php';

    App::import('Controller', null);
    App::import('Controller', 'App');

    require_once( CORE_PATH . 'vendors' . DS . 'cakeamfphp'.DS.'amf-core'.DS.'app'.DS. 'CakeGateway.php');

  3. Edit app/vendors/cakeamfphp/amf-core/app/CakeActions.php, line 195
    • Change to $controller->Component->init($controller);
    Before:
    Download code $controller->_initComponents();
    After:
    Download code $controller->Component->init($controller);

  4. Edit app/vendors/cakeamfphp/amf-core/app/CakeGateway, line 25
    Change vendor calls to:
    • require_once(APP.'vendors'.DS.'cakeamfphp'.DS.'amf-core'.DS.'app'.DS.'Gateway.php');
    • require_once(APP.'vendors'.DS.'cakeamfphp'.DS.'amf-core'.DS.'app'.DS.'CakeActions.php');
    Before:
    Download code vendor('cakeamfphp'.DS.'amf-core'.DS.'app'.DS.'Gateway');
    vendor('cakeamfphp'.DS.'amf-core'.DS.'app'.DS.'CakeActions');
    After:
    Download code require_once(APP.'vendors'.DS.'cakeamfphp'.DS.'amf-core'.DS.'app'.DS.'Gateway.php');
    require_once(APP.'vendors'.DS.'cakeamfphp'.DS.'amf-core'.DS.'app'.DS.'CakeActions.php');


That should wrap things up!

 

Comments 743

CakePHP Team Comments Author Comments
 

Bug

1 path problem in step 4

Edit app/vendors/cakeamfphp/amf-core/CakeGateway, line 25

Replace with:

Edit app/vendors/cakeamfphp/amf-core/app/CakeGateway, line 25
Posted Jul 24, 2008 by Finjon Kiang
 

Comment

2 cakeswxphp

Hey ryan,


You should try cakeswxphp - which you mentioned in your post - some time, it contains an amf gateway, and has a branch for cakephp 1.2 :-)
Posted Aug 5, 2008 by Wouter Verweirder
 

Comment

3 A note about HTTP_RAW_POST_DATA

Okay, so I just got CakeAMF working with Cake 1.2.0.7692-rc3. But only after an hour of tracing what CakeAMF was doing wrong.

On line 138 of:
cakeamfphp/amf-core/app/Gateway.php

You should see the following code:
$GLOBALS['amfphp']['actions'] = $this->actions;
Just below that, add this if condition:


if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])){
            $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input');
        }

If none of your calls to the service are going through.. this is most likely the problem.

I would suggest the developers of CakeAMF do this to their source because that's how AMFPHP also does it.
Posted Dec 19, 2008 by Navneet Behal