WebORB for PHP Login Example using Flex 3 and Cairngorm 2.2.1
August 8th, 2007
UPDATE 23/12/07: The tutorial and source code have been updated using Flex Builder 3 Beta 3.
I’ve been playing around with WebORB for PHP for developing Flex remoting services and it’s just awesome. WebORB gives you well documented product information including a service browser, tons of examples, code generator etc.
However, one thing I’ve missed is a WebORB for PHP example using Flex and Cairngorm… So I decided to write it down on my blog. It based on Alex Uhlmann’s CairngormLogin Sample modified by Neil Webb.
Example
Instruction
- You’ll need the following sources:
- WebORB for PHP (v2.0.2)
- Cairngorm (2.2.1)
- Alex Uhlmann’s CairngormLogin Sample
- Install WebORB as described in “GETTING STARTED – WEBORB INSTALLATION“.
-
Open Flex Builder and create a new Flex Project called “CairngormLogin”. As Mike Potter pointed out you don’t need to select Flex Data Service as server type which mentioned by the WebORB documentation, just “Other/None” using a
services-config.xmlas described in step 5.
-
Don’t forget to add the
Cairngorm.swcto your library path.
-
Create
services-config.xmland modify the value of theendpoint urito{yourWebORBInstallationFolder}/Weborb/index.php. Save it into the root of your project folder.[UPDATE 10/06/07] Flex Builder 3 Beta 2 needs a valid port as well. For more information about it read this thread on Adobes Flex Builder 3 forum.[/UPDATE]
services-config.xml ( Download code )
-
<?xml version="1.0" encoding="UTF-8"?>
-
<services-config>
-
<services>
-
<service id="amfphp-flashremoting-service"
-
class="flex.messaging.services.RemotingService"
-
messageTypes="flex.messaging.messages.RemotingMessage">
-
<destination id="GenericDestination">
-
<channels>
-
<channel ref="my-amf"/>
-
</channels>
-
<properties>
-
<source>*</source>
-
</properties>
-
</destination>
-
</service>
-
</services>
-
-
<channels>
-
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
-
<endpoint uri="http://localhost:80/weborb/Weborb/index.php" class="flex.messaging.endpoints.AMFEndpoint"/>
-
</channel-definition>
-
</channels>
-
</services-config>
-
-
Open your project properties window with a right mouse click on your project folder within Flex Builder to add the
services-config.xmlas a-servicesargument to the Flex compiler
- Copy all files of Alex Uhlmann’s CairngormLogin Sample into your project folder.
- Update the
LoginDelegate.as,LoginCommand.asandLoginPanel.mxmlto the latest Cairngorm package (v. 2.2.1 beta) as Neil Webb described. At the end you can check your work with my files as well. -
Now you have to create the remoting service called
getUseradding aLogin.phpto{yourWebORBInstallationFolder}/Services/com/adobe/cairngorm/samples/login/.Login.php ( Download code )
-
<?php
-
-
require_once("vo/LoginVO.php");
-
-
class Login
-
{
-
-
public function getUser(LoginVO $loginVO)
-
{
-
if ($loginVO->username == "admin" && $loginVO->password == "admin")
-
{
-
$adminVO = new LoginVO();
-
$adminVO->username = $loginVO->username;
-
$adminVO->password = $loginVO->password;
-
return $adminVO;
-
}
-
else
-
{
-
throw new Exception("Invalid username or password, please try it again.");
-
}
-
-
}
-
}
-
-
?>
-
-
-
The remoting service needs a Value Object (VO) to transfer the data between the application tier. Therefore create a VO named
LoginVO.phpand put it into{yourWebORBInstallationFolder}/Services/com/adobe/cairngorm/samples/login/vo/LoginVO.php ( Download code )
-
<?php
-
class LoginVO
-
{
-
var $username;
-
var $password;
-
var $loginDate;
-
}
-
?>
-
-
Modify the ServiceLocator named
Services.mxmlfor adding the remoting service created in step 9. Note: The destination for WebORB is calledGenericDestination.Services.mxml ( Download code )
-
<?xml version="1.0" encoding="utf-8"?>
-
<cairngorm:ServiceLocator
-
xmlns:mx="http://www.adobe.com/2006/mxml"
-
xmlns:cairngorm="com.adobe.cairngorm.business.*">
-
<mx:RemoteObject
-
id="loginService"
-
destination="GenericDestination"
-
source="com.adobe.cairngorm.samples.login.Login"
-
showBusyCursor="true"
-
result="event.token.resultHandler(event);"
-
fault="event.token.faultHandler(event);">
-
</mx:RemoteObject>
-
</cairngorm:ServiceLocator>
-
-
-
Modify the
LoginDelegate.asto call the remoting service namedloginService.LoginDelegate.as ( Download code )
-
package com.adobe.cairngorm.samples.login.business
-
{
-
import com.adobe.cairngorm.business.ServiceLocator;
-
import com.adobe.cairngorm.samples.login.vo.LoginVO;
-
-
import mx.rpc.AsyncToken;
-
import mx.rpc.IResponder;
-
-
public class LoginDelegate
-
{
-
private var responder : IResponder;
-
private var service : Object;
-
-
public function LoginDelegate( responder : IResponder )
-
{
-
this.service = ServiceLocator.getInstance().getService( "loginService" );
-
this.responder = responder;
-
}
-
-
public function login( loginVO : LoginVO ): void
-
{
-
var token : AsyncToken = service.getUser(loginVO);
-
token.resultHandler = responder.result;
-
token.faultHandler = responder.fault;
-
}
-
-
}
-
}
-
-
-
Modify the
LoginCommand.asto respond the service call.LoginCommand.as ( Download code )
-
package com.adobe.cairngorm.samples.login.commands
-
{
-
import com.adobe.cairngorm.commands.Command;
-
import com.adobe.cairngorm.control.CairngormEvent;
-
import com.adobe.cairngorm.samples.login.business.LoginDelegate;
-
import com.adobe.cairngorm.samples.login.control.LoginEvent;
-
import com.adobe.cairngorm.samples.login.model.ModelLocator;
-
-
import mx.rpc.IResponder;
-
-
public class LoginCommand implements Command, IResponder
-
{
-
private var model : ModelLocator = ModelLocator.getInstance();
-
-
public function execute( event : CairngormEvent ) : void
-
{
-
model.login.isPending = true;
-
-
var delegate : LoginDelegate = new LoginDelegate( this );
-
var loginEvent : LoginEvent = event as LoginEvent;
-
delegate.login( loginEvent.loginVO );
-
}
-
-
public function result( event : Object ) : void
-
{
-
model.login.loginVO = event.result;
-
model.login.loginDate = new Date();
-
model.login.isPending = false;
-
-
model.workflowState = ModelLocator.VIEWING_LOGGED_IN_SCREEN;
-
}
-
-
public function fault( event : Object ) : void
-
{
-
model.login.statusMessage = event.fault.faultString;
-
model.login.isPending = false;
-
-
model.workflowState = ModelLocator.VIEWING_ERROR_SCREEN;
-
}
-
}
-
}
-
-
One of the big advantage using remoting services is providing well-typed objects over the application tier called “client-server-class mapping”. For ensure this you have to correspond your client-side Value Object called
LoginVO.asto itsRemoteClassusing[RemoteClass(alias="com.adobe.cairngorm.samples.login.vo.LoginVO")]LoginVO.as ( Download code )
-
package com.adobe.cairngorm.samples.login.vo
-
{
-
import com.adobe.cairngorm.vo.ValueObject;
-
-
[RemoteClass(alias="com.adobe.cairngorm.samples.login.vo.LoginVO")]
-
-
[Bindable]
-
public class LoginVO implements ValueObject
-
{
-
public var username : String;
-
public var password : String;
-
public var loginDate : Date;
-
}
-
}
-
That’s all
Download
Note: In the following *.zip-file I’ve changed some more code lines for customizing the appearance of the example which I don’t described above. Anyway, have fun
Source: CairngormLoginExampleWebORB.zip
(Downloads: 4642)



August 8th, 2007 at 1:31 pm
[...] Contact the Webmaster Link to Article open source WebORB for PHP Login Example using Flex 3 and Cairngorm 2.2.1 » Posted [...]
August 8th, 2007 at 6:26 pm
It is nothing wrong to be making Flex on Mac OS X.
I am happy with my Mac too and just complete a project using WebORB 2 PHP.
August 10th, 2007 at 7:15 pm
[...] «« WebORB for PHP Login Example using Flex 3 and Cairngorm 2.2.1 [...]
October 2nd, 2007 at 8:00 pm
Worked, but just upgraded to FlexBuilder3 Beta 2 and I now get this error:
Invalid endpoint port ” specified for channel definition ‘my-amf’.
Anyone else getting this? I’m not sure what the source of the problem is. Flexbuilder or Cairngorm? I also have the CairngormEnterprise.swc – same result with or without it, but separate question: do I need this? Maybe not. Unsure.
October 6th, 2007 at 4:28 pm
@Andrew: This is a known issue upgrading to Flex Builder 3 Beta 2. To solve this add a port number to your endpoint located in “services-config.xml”.
You’ll find more Information here: http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=72&catid=651&threadid=1303695&enterthread=y
P.S. I have updated the source within “CairngormLoginExampleWebORB.zip” as well
-sectore
October 30th, 2007 at 5:30 pm
[...] http://www.websector.de/blog/2007/08/08/weborb-for-php-login-example-using-flex-3-and-caingorm-221/ [...]
March 29th, 2008 at 5:36 pm
[...] Cairngorm – Login Demo (basierend auf Alex Uhlmanns Beispiel) [...]
April 3rd, 2008 at 7:02 am
Hey all,
Great example! I made my test app and am not having any luck. My cairngorm command fails every time. The application is doing a full trip (i think) because the error is falling in the fault handler of my command. I am close and would love a little help.
Here is my error:
Channel.Connect.Failed error NetConnection.Call.BadVersion: : url: ‘http://www.andomation.com:80/weborb/index.php’
My isp is running php5
Joe
April 3rd, 2008 at 7:28 am
Changed my services-config.xml to
http://www.andomation.com:80/weborb/Weborb/index.php
and now it just hangs
April 3rd, 2008 at 8:26 am
Joe,
check out your traffic based on AMF using a tool such as ServiceCapture to avoid any corrupted calls.
-Jens
May 12th, 2008 at 1:35 pm
hi,
I tried to test the CairngormLoginExampleWebORB.zip. But when I run it, and test it I get the error “send failed” is there something wrong with my weborb?
pls help me
thnx
May 13th, 2008 at 6:01 am
Regarding Joe’s error:
Channel.Connect.Failed error NetConnection.Call.BadVersion: : url: ‘http://www.andomation.com:80/weborb/index.php’
You need to specify the endpoint url to point to the weborb.php file, not index.php.
So the endpoint uri in your services-config.xml should look something like this:
May 13th, 2008 at 6:03 am
The XML snippet got stripped out, so imagine there are angled brackets on either end of this:
endpoint uri=”http://localhost:80/weborb/Weborb/weborb.php” class=”flex.messaging.endpoints.AMFEndpoint”/
May 15th, 2008 at 2:18 am
I’m not sure what I’m missing but when the submit button is clicked I get the Send Failed error? Not really sure how to troubleshoot this. I’m monitoring HTTP activity and it shows a “HTTP/1.1 200 OK”.
Can anyone help?
May 15th, 2008 at 2:35 am
I noticed my endpoint URL was incorrect. However, after correcting it….it now just hangs.
On compile in Flex Builder I’m getting the following error:
“ReferenceError: Error #1056: Cannot create property isError on mx.messaging.messages.AcknowledgeMessage.”
Ideas?
June 11th, 2008 at 10:47 pm
Hi Jens,
well I finally got around to installing xampp & weborb today so I was able to follow the tutorial ( how long has it been since 360|Flex Milan? See, it only took me a few months
)
The only thing I can fault you on is that you spelled my surname incorrectly – meh, happens all the time
Thanks very much for the tutorial. Next on the agenda … the pureMVC example.
June 11th, 2008 at 11:28 pm
[...] the end product (which was simply an updated version of the original) and used it to write his own tutorial demonstrating how to get the login example running with [ the PHP version of ] WebOrb (an open [...]
June 12th, 2008 at 7:10 am
Hey Neil,
nice to see you here again and sorry about your spelled surname – it has been fixed now
-Jens
June 12th, 2008 at 11:40 am
No problem at all – thanks for the fix :]
September 15th, 2008 at 8:38 pm
Very good tutorial!!!
Just one doubt: what if I want to pass a recordset instead of an object?
How to configure the corresponding VO in flex?
Anybody can enlight me?
Thanks
November 8th, 2008 at 7:15 pm
I have the same problem!! as tammy
—I tried to test the CairngormLoginExampleWebORB.zip. But when I run it, and test it I get the error “send failed” is there something wrong with my weborb?—
or there’s a configuration error???
thanks in adavance!!!
November 28th, 2008 at 11:21 pm
To avoid the “Send failed” error, the flex files must be loaded from the web server, and not locally.
December 4th, 2008 at 11:48 am
[...] exemple qui à l’air sympa surtout au niveau des effets très tendance web 2.0 [...]