Second Physical Communication Laboratory

Tag: cakephp Flex CakeSWXPHP

CakeSWXPHP

by admin on 1 月.05, 2010, under FlexSDK3 Programming

If you want to use RemoteObject on CakePHP, you can use “CakeSWXPHP”.

This Knowledge is refered to 株式会社ヒューマンオーク’s web site (http://www.human-ook.jp/company.html)

CakeSWXPHP allows SWX to call CakePHP controllers. CakePHP is a rapid development framework for PHP.

Codeing

  • controller
    class HelloWorldsController extends AppController {
    	var $name ='HelloWorlds';
    	var $uses = '';
    	function hello(){
    		return 'HelloWorlds';
    	}
    }
  • Flex code
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
    minWidth="1024" minHeight="768" creationPolicy="all">
    <mx:Button label="ボタン" click="onClickBtn()"/>
    <mx:RemoteObject id="srv"
    	endpoint="{'http://localhost/cake/amf.php'}"
    	destination="MyAmfs"
    	source="HelloWorldsController"
    	result="handleResult(event)"
    	fault="handleError(event)">
    </mx:RemoteObject>
    <mx:Script>
    <![CDATA[
    	import mx.controls.Alert;
    	import mx.rpc.events.FaultEvent;
    	import mx.rpc.events.ResultEvent;
    
    	public function onClickBtn():void{
    		srv.hello();
    	}
    
    	public function handleResult(re:ResultEvent):void{
    		Alert.show(re.result.toString());
    	}
    
    	public function handleError(fe:FaultEvent):void{
    		Alert.show(fe.messageId);
    	}
    ]]>

RemoteObject
endpoint: able to access amf.php on the cakePHP’s URL in the webroot.
source: Controller’s name
result: connection success
fault: connection fault

Tips

Use models
return $this -> Model -> findall();
flex can get the objectarray.

debuging tools
localhost/cake/explorer/

Leave a Comment : more...