So at work we are experimenting with WebOrb to ditch XML. No for good but definatly when there will be a lot of parsing. Anyway, our PHP Programmer downloaded WebOrb and we looked at the examples but the example were either banking on you having previous Flex Data Services experience or they were not that good in my opinion. The most crucial info was not even on the tutorial application page. So I’m going to walk you through the tutorial with the modification I used to get it working from various Google Searches. Mainly no service-cofig.xml.
- Ok, first thing is go to WebOrb’s website http://www.themidnightcoders.com/weborb/php/index.htm
I’m using the PHP version, and make sure you have PHP5. - Upload it to your server on put it in you localhost folder. We have it in a folder called “WebOrb” (http://YOUR_SITE/WebOrb)
- Create a new project in Flex.
- Go to the WebOrb tutorial. http://www.themidnightcoders.com/weborb/php/gettingstarted.htm skip down to the heading CONFIGURATION – FLEX BUILDER follow those directions. The remote config on our set up is http://YOUR_SITE/WebOrb/Weborb/WEB-INF/flex/remote-config.xml The last direction on the site is the server code (PHP) that goes in the Services folder located in http://YOUR_SITE/WebOrb/Services/InfoServices (with our current set-up)
- Now let’s go to another page and get the info on how this is connection to the service because that tutorial told me nothing about service-cofig.xml. Invoking PHP objects w/ Remote Object.
- don’t worry about this skip it (if you do worry go to the remote-config.xml to check it out http://YOUR_SITE/WebOrb/Weborb/flex):< <destination id=”destination-name”>
<properties>
<source>Your.PHP.ClassName</source>
</properties>
</destination>we will be using a GenericDestination which is already in the remote-config.xml:<destination id=”GenericDestination”>
<properties>
<source>*</source>
</properties>
</destination>
the source tag will be filled in the Flex code. - now we will fill out the mxml RemoteObject:
< mx:RemoteObject id="InfoServiceObj" destination="GenericDestination" endpoint="http://YOUR_SITE/WebOrb/Weborb/index.php" fault="onFault(event)" showbusycursor="true" fault="onFault(event)"> < mx:method name="getComputerInfo" result="onResult(event)"> mx:RemoteObject> endpoint="http://YOUR_SITE/WebOrb/Weborb/index.php" and destination="GenericDestination" are what make this RemoteObject flexible. All you have to do is change you destination and your ready to go for another service. Endpoint is like you gateway in AMFPHP (to all the classes of weborb)
- Lastly here are the handlers for the modified example.mxml, dump this in over the old scripts
import mx.rpc.remoting.*; import mx.controls.*; import mx.rpc.events.* public function onCreationComplete():void { InfoServiceObj.getComputerInfo.addEventListener("result", onResult); } public static function onFault(event:FaultEvent):void { Alert.show(event.fault.faultString, 'Error'); } private function onResult(event:ResultEvent):void { var computerInfo:Object = event.result; currentUserText.text = computerInfo.currentUser; processIdText.text = computerInfo.phpProcessId; osText.text = computerInfo.operatingSystem; phpVersionText.text = computerInfo.phpVersion; invokeButton.enabled = true; } private function getInfo():void { invokeButton.enabled = false; currentUserText.text = ""; processIdText.text = ""; osText.text = ""; phpVersionText.text = ""; InfoServiceObj.getComputerInfo(); } and put a click handler on the button click="getInfo()"
here is the code I hope it helps:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
import mx.rpc.remoting.*;
import mx.controls.*;
import mx.rpc.events.*
public function onCreationComplete():void
{
InfoServiceObj.getComputerInfo.addEventListener("result", onResult);
}
public static function onFault(event:FaultEvent):void
{
Alert.show(event.fault.faultString, 'Error');
}
private function onResult(event:ResultEvent):void
{
var computerInfo:Object = event.result;
currentUserText.text = computerInfo.currentUser;
processIdText.text = computerInfo.phpProcessId;
osText.text = computerInfo.operatingSystem;
phpVersionText.text = computerInfo.phpVersion;
invokeButton.enabled = true;
}
private function getInfo():void
{
invokeButton.enabled = false;
currentUserText.text = "";
processIdText.text = "";
osText.text = "";
phpVersionText.text = "";
InfoServiceObj.getComputerInfo();
}
]]>
</mx:Script>
<mx:RemoteObject destination="GenericDestination" source="InfoService" id="InfoServiceObj" endpoint="http://YOUR_SITE/WebOrb/Weborb/index.php" fault="onFault(event)" showBusyCursor="true">
<mx:method name="getComputerInfo" result="onResult(event)" />
</mx:RemoteObject>
<mx:Panel x="10" y="10" width="329" height="189" layout="absolute" title="Info Service Example">
<mx:Label x="10" y="10" text="Current user:"/>
<mx:Label x="10" y="36" text="PHP Process ID:"/>
<mx:Label x="10" y="62" text="OS/Architecture:"/>
<mx:Label x="10" y="88" text="PHP Version:"/>
<mx:TextInput x="113" y="8" width="186" editable="false" id="currentUserText"/>
<mx:TextInput x="113" y="34" width="186" editable="false" id="processIdText"/>
<mx:TextInput x="113" y="60" width="186" editable="false" id="osText"/>
<mx:TextInput x="113" y="86" width="186" editable="false" id="phpVersionText"/>
<mx:Button id="invokeButton" x="166" y="116" label="Get Computer Info" click="getInfo()" />
</mx:Panel>
</mx:Application>
Hi,
Did you manage to get the secure part working?
Any chance you could do a quick writeup if you did???
I would like to know how to be able to do a quick login using mysql credentials and not allow access to the services (classes) unless the user is logged in/has rights.
I haven’t messed with security. Sorry