Previous Next
Programmers Guide for PHP 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:

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.

  1. Download PHPEclipse from http://sourceforge.net/project/showfiles.php?group_id=57621
  2. Unzip the download PHPEclipse and copy to the installed Eclipse folder
  3. Start Eclipse and open the perspective of PHP.
  4. Figure 2.1 - Eclipse with PHP Ecilpse

Copying Generated Source and Library to Eclipse Project

You can copy the generated persistent code to Eclipse project and develop an application.

  1. Open Eclipse and select File > New > Project... from menu
  2. Figure 2.2 - Create a new project
  3. Select Java Project, click Next >.
  4. Figure 2.3 - Select PHP project
  5. Enter "AirportProject" for the project name.
  6. Figure 2.4 - Enter the Project name
  7. The AirportProject is created and shown on the Navigator.
  8. Figure 2.5 - The PHP project is created
  9. Copy the PHP persistent code from the specified output folder.
  10. Figure 2.6 - Copy the generated code
  11. Paste the Java persistent code on the AirportProject in Package Explorer.
  12. Figure 2.7 - Paste in Eclipse
  13. All the generated PHP persistent codes are copied to the AirportProject.
  14. Figure 2.8 - The generated PHP files will copy to the Eclipse project directory

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.

  1. Open the src/ormsamples/CreateAirportData.php file. The following is the original code
  2. <?php
    require_once( realpath(dirname(__FILE__)).'/lib/phporm/ezpdo_runtime.php');
    /**
    * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
    *
    * This is an automatic generated file. It will be regenerated every time
    * you generate persistence class.
    *
    * Modifying its content may cause the program not work, or your work may lost.
    */

    /**
    * Licensee: Demo
    * License Type: Purchased
    */
    class CreateFlightData {
    public function createTestData() {
    $flight = FlightFactory::createFlight();
    // Initialize the properties of the persistent object
    $flight->save();

    $plane = PlaneFactory::createPlane();
    // Initialize the properties of the persistent object
    $plane->save();
    }
    }

    $createFlightData = new CreateFlightData();
    $createFlightData->createTestData();
    ?>
  3. Modify to create Flight and Plane instance and create the relationship between them
  4. 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.

    Figure 2.9 - There is no record in the tables
  5. Open command prompt and go to the project folder. Type "php CreateFlightData" to execute the CreateFlightData code.
  6. The execution result:

    Figure 2.10 - The execute result
  7. After executing the CreateAirportData.java, new records are created in tables.
  8. Figure 2.11 - The records are created on database

Previous Next
Visual Paradigm International Limited
Website: www.visual-paradigm.com
E-mail: support@visual-paradigm.com