Archive for September, 2009

CakePHP doesn’t like autoload() with vendor app import!

Tuesday, September 22nd, 2009

So, it would seem that if you decide that you want your vendor plugin to work nicely with cake, by having it conform to Pear folder directory structure and naming convention, and then right yourself a nice autoload() function to register with php (via spl_autoload_register()), you CANNOT use the App::import alongside this.
Why? Because Cake’s lovely App::import does a require() not a require_once()… Go figure!

So here is the problem:
You have App::import()’d your vendor plugin. It registers itself as an autoloader.
You have your 2nd vendor plugin, (which conforms to a Pear style structure also).
You explicitly App::import(’vendor’,'2nd item’,array(’file’=>’path/to/vendor/file.php’));
Cake has a fit and dies saying you “cannot redeclare “.
Brilliant Cake well done! Another reason to use Zend Framework…

As a solution I have altered the cake source code to make sure the require() is in fact a require_once(). I have yet to see the impact of such a change on any other import()’s. See below for alteration:
File: cake/libs/configure.php
Line: 975
Previous: “require($file);”
Change: “require_once($file);”

CakePHP CPAMF flex VO object flash integration

Monday, September 21st, 2009

Well thank god for that!

After a few days of stressing and pulling out hair, and with the help of one young dutch genius we managed to resolve the cake cpamf plugin VO integration.

Firstly, things to know about cake:

  1. Cake REQUIRES all models to be in the “models” directory.
  2. CPAMF plugin is installed in in the “plugins” directory.
  3. You can view all controllers/services at /cpamf/browser
  4. The gateway that flash connects to is /cpamf/gateway (not /cpamf/gateway.php as the default seems to think).
  5. CPAMF does NOT use the vendor/services/vo directory that is inside the amfphp part of the plugin.

Flash RemoteClass alias can be any path

e.g.

package
[RemoteClass(alias="org.test.TestOp")]
/**
* @author
*/
public class TestOP
{
public var username:String;
public var password:String;
public var id:int;
public function TestOP( username:String=null, password:String=null, id:int=0) {
this.username = username;
this.password = password;
this.id = id;
}
}
}

This class path MUST be represented in the PHP class using the _explicitType = ‘org.test.TestOp’. Once this is done you can pass back this class through any controller method.

e.g.

class TestOp {
public $_explicitType = 'org.test.TestOp';
public $username;
public $password;
public $id;
}

So, as you can see from the above, the PHP class MUST have the full package path to the flash class, and your class will be “models/test_op.php” as cake has a horrid non-pear style naming convention.