The relationship between client code and server code in
Flex differs from the traditional relationship in a server template.
In a traditional relationship, a server template mixes server
code with client code. When the client queries a database, it dynamically
embeds HTML code with returned data.
Flex, however, separates client code from server code. The remote
service returns only data. Flex binds the returned data to user
interface components in the client application.
In Flash Builder, select File > New > Flex Project.
Specify PHP_Service for the project name and set the Application
Server Type to PHP.
Note: If
you forget to set the application server type when you create the
project, you can later specify the server type from the Project
Properties page.
Click Next. Verify your PHP configuration and click Validate
Configuration.
For Output Folder, specify the PHP_Service folder
you created previously.
Flash Builder suggests a default location
for the output folder. Use the location that already contains EmployeeService.php.
Here is the location previously specified:
<Web Root>/PHP_Service/
Click Finish.
The Flash builder source editor opens
to PHP_Service.mxml.
Select Design to open the editor in Design mode. Add a DataGrid
control to the application:
The DataGrid component is available
under Data Controls in the Components view. Drag the DataGrid control
to the design area.
With the DataGrid selected, in the Properties view, click
the Bind to Data button.
The Bind to Data button is next to
the Data Provider field in the Properties view.
In the No Services Defined dialog, click Yes to connect to
a service.
In the New Flex Service wizard, select PHP. Click Next.

Flash Builder provides multiple ways to connect
to a data service. In this scenario, you first create the user interface.
then from a user interface component, you can connect to a service
and specify the remote operation.
Click Browse and navigate to the PHPservice.php file you
created previously. Click Finish.
The path to the file is:
<Web Root>/PHP_Service/services/EmployeeService.php
The
Data Services View now displays the EmployeeService.
With the DataGrid selected, again click the Data Provider
button in the Properties view.
The Bind to Data dialog opens
with New Service Call selected.
EmployeeService is the only
service available in the Flex project.
getBooks() is
the only operation available in the service.
In the Bind to Data dialog, select Configure Return Type
to define the data type for returned data.
Flex needs to know
the return data type to access service operations. The EmployeeService
service does not define the data type for returned data. Flash Builder
uses client-side typing to define a custom data type for the returned data.
In the Configure Return Type dialog, Auto-Detect the Return
Type is selected by default. Click Next.
Specify Employee for the name of the
type. Click Finish.
The EmployeeService returns a complex
data type representing a database record for an employee. The custom
type Employee provides access to each field of the record.
View
the properties of the Employee data type returned by the service.
Click Finish.

When Flash Builder configures
a return type it accesses the database to create a value object.
The properties of the custom data type are derived from the value object.
You can view and modify the properties of the data type before proceeding.
In the Bind to Data dialog, click OK.
Flash Builder
binds the data returned from the service call to the DataGrid component.
It modifies the columns of the DataGrid, binding the value returned
for each Employee property to a column in the DataGrid.
Make sure the DataGrid is still selected. In the Properties
view, click Configure Columns and then do the following steps:
Select the hire_date column. Click Delete
to delete the column.
Similarly, delete all columns except emp_no, first_name,
and last_name.
Select the emp_no column. Click Up to move it to the first
position.
In the Header Text field, rename the column to ID.
Similarly, rename the first_name and last_name columns.
Click OK.
With the DataGrid still selected, in the Properties view,
specify False for the editable property.
Select File > Save to save the application file. Then
select Run > Run PHP_Service to run the application.
The
application runs in a web browser.