Chapter 2 -Configuring Source and Library in Eclipse
Chapter 2 - Configuring Source and Library in Eclipse
In Chapter 1, you have generated PHP code, exported database schema (DDL) and persistent library. In this chapter, we will show you how to import the generated code from Chapter 1 to Eclipse. You will create a new project and copy the generated persistent code and library to Eclipse, and you can further your development with the generate model efficiently in Eclipse.
In this chapter:
- Install PHP plugin for Eclipse
- Copying Generated Source and Library to Eclipse Project
- Modifying the Sample Program to Test the Generated PHP Model
Installing PHP plugin for Eclipse
The PHPEclipse is a PHP plugin can support for Eclipse IDE Framework. It provides a flexible environment to develop PHP project just like develop Java project in Eclipse. Some features are PHP parser, debugger, code formatter, outline view, templates...etc.
- Download PHPEclipse from http://sourceforge.net/project/showfiles.php?group_id=57621
- Unzip the download PHPEclipse and copy to the installed Eclipse folder
- Start Eclipse and open the perspective of PHP.
Copying Generated Source and Library to Eclipse Project
You can copy the generated persistent code to Eclipse project and develop an application.
- Open Eclipse and select File > New > Project... from menu
- Select Java Project, click Next >.
- Enter "AirportProject" for the project name.
- The AirportProject is created and shown on the Navigator.
- Copy the PHP persistent code from the specified output folder.
- Paste the Java persistent code on the AirportProject in Package Explorer.
- All the generated PHP persistent codes are copied to the AirportProject.
Modifying the Sample Program to Test the Generated PHP Model
Now the AirportProject is able to compile, you can modify the code in generated sample to test the persistent class interact with the created database.
- Open the src/ormsamples/CreateAirportData.php file. The following is the original code
<?php
require_once( realpath(dirname(
__FILE__)).
'/lib/phporm/ezpdo_runtime.php');
class CreateFlightData {
public function createTestData() {
$flight = FlightFactory::createFlight();
$flight->save();
$plane = PlaneFactory::createPlane();
$plane->save();
}
}
$createFlightData =
new CreateFlightData();
$createFlightData->createTestData();
?>
- Modify to create Flight and Plane instance and create the relationship between them
public function createTestData() {
echo "Create Flight\n";
$flight = FlightFactory::createFlight();
$flight->departureTime = "20060203";
$flight->departingAirport = "Kansai International Airport";
$flight->arrivingAirport = "Hong Kong International Airport";
echo "Create Plane\n";
$plane = PlaneFactory::createPlane();
$plane->planeType = "747 plane";
$plane->maxSpeed = (float)967;
$plane->maxDistance = (float)8232;
echo "Create the relationship between Flight and Plane\n";
$plane->flights[] = $flight;
echo "Save the Plane and the Flight object\n";
$plane->save();
}
There is no record for the Flight and Plane tables before the execution of the sample application.
- Open command prompt and go to the project folder. Type "php CreateFlightData" to execute the CreateFlightData code.
The execution result:
- After executing the CreateAirportData.java, new records are created in tables.
|
|
| Visual Paradigm International Limited |
| Website: |
www.visual-paradigm.com |
| E-mail: |
support@visual-paradigm.com |
|