Skip to content


PHP and Flex with Kerkness and Claire

The following example shows a simple Flex application using Claire that communicates with a PHP server running Kerkness.

Click here to view the demo application

Click here to view the demo source

The demo application starts out by displaying a form which has 2 input fields.  When submitted the value of the form is submitted to the PHP service which validates the submission and returns a response.  If there are no errors the results are displayed.

ClaireKerkness.mxml

The main application MXML file contains the ViewController and a ViewStack with both our FormView and ResultView as children. When the view controller dispatches the mainViewChange event a handler function changes the displayed view.

model/Views.as

This is a very simple Actionscript class which defines a couple of static constants to use as the names for our two views.

model/NameModel.as

A simple Actionscript class which we use as a data model.  When a response is returned we update this model.

NOTE: In this example our NameModel is a Singleton Class because we only want one instance.  This doesn’t have to be the case. You might want to create many instances of a data model if you expect many records of similar data.

views/FormView.mxml

FormView is an MXML component that contains a couple of form elements and a ClaireService component which is used to send a HTTPService request to the Kerkness backend. If an error is returned the error message is displayed.  If a response is returned we update the NameModel and change the currentView to our ResultView.

views/ResultView.mxml

ResultView is a simple MXML component which displays content from the NameModel.

kerk/module/demo/submitform.php

This is the PHP file which accepts our form submission. Check out the kerkness tutorials for details on how the kerkness framework handles requests.

PHP Source Code


if( ! $_POST['firstname'] || ! $_POST['lastname'] )
{
 	$kerk->throwError('Incomplete Submission...', true );
}

$fullName = $_POST['firstname']. ' ' .$_POST['lastname'];

$kerk->addContent('fullName', $fullName); 

Posted in Actionscript, Code, PHP, Tutorials.

Tagged with , , .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.



close