Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Developing PHP Applications with NetBeans and Eclipse : Page 3

Discover the convenience of developing PHP applications using two of the most popular and powerful IDEs on the market, NetBeans and Eclipse.


advertisement

Installing Eclipse PDT for PHP

The PDT project creates open source PHP development tools for the Eclipse platform. To run PDT 2.0 for Eclipse you must have the JDK or JRE installed on your computer (the minimum required version is 5.0). Then download the latest released PDT All-In-One Package from the link (select the package for Windows) (see Figure 9). Unzip the downloaded archive in a convenient folder and then run the eclipse.exe file to install the package.
 
Figure 9. Download PDT 2.0: Click the Download button and then select the Windows package.

Creating a PHP Project with Eclipse

The PHP Development Tools Project, or PDT, offers these features:

  • Intuitive and easy to learn
  • Seamless integration with other Eclipse projects
  • Adherence to Eclipse standards
  • Extensibility
  • Continuous support of PHP developments
  • Support for XDebug or Zend Debugger to boost your productivity when fixing bugs in PHP applications
  • Code assistant and syntax highlighting

Developing the Sample Project

 
Figure 10. New Eclipse PHP Project: Here are the settings you should use when creating the PHP project stub using Eclipse.
This section walks you through the process of developing the same PHP project, booksPHP, that you created earlier with NetBeans, but this time, you'll use Eclipse. The process is similar. Start by creating a project stub as follows:
  1. Launch Eclipse.
  2. From the File main menu select the New → Other option (the New window appears).
  3. Expand the PHP node and select the PHP Project option. Then click Next.
  4. In the New Project window enter a project name, the target PHP version, and select the project layout and JavaScript support settings. For this project, type booksPHP in the Project name field, and activate the "Enable JavaScript support for this project" option. In addition, click the "Create project from existing source" radio button, because you don't want to use the default workspace. Instead, use the server workspace (Apache HTTP Server in this case). Use the Browse button to navigate to your server deployment folder. Leave everything else set to the default (see Figure 10). Click Next to continue.

  5. Author's Note: Make sure that the deployment folder you choose is empty, because Eclipse will try to associate every file and folder to the selected deployment folder. As a tip, for this project, create an empty folder under the deployment folder named booksPHP, especially for this project. Then set the Directory field to point to the booksPHP folder, as shown in Figure 10.

  6. On the next page, configure the PHP include path. Here you can specify files, projects and libraries to be included in your project. You don't need such resources for booksPHP, therefore leave everything set to the default and just click Next.
  7. You'll see a build path screen where you can specify resources to be included in build process. For now, leave everything set to the default, and click Finish.
Eclipse generates the stub booksPHP project, which appears in the Eclipse Project Explorer view.

Implementing Index.php—Eclipse Style

You've already seen exactly what index.html contains (see Listing 1), so you can jump directly to the implementation. The Eclipse steps to accomplish this are:
 
Figure 11. Eclipse Code Assistant: Here's the Eclipse code assistant in action after typing an initial opening-tag angle bracket.
  1. In the Project Explorer view, right-click on the project name and select the New → Other option.
  2. In the New window, expand the Web node and select the HTML leaf. Click Next.
  3. On the next screen, specify the page name (index.html) in the File name field. Click Next.
  4. Select a template for the initial content in the HTML page. For example, you can select New HTML file (4.01 transitional). Click Finish.
Eclipse will generate and open the new index.html file. Alter its content the same way you did in the NetBeans project (see Listing 1). Like NetBeans, when you're entering HTML, Eclipse provides a code assistant (see Figure 11).


PHP Perspectives and Views

As you may know, Eclipse uses a set of views that support various technologies. Each set of views is called a "perspective." The connection between perspectives and their views is just a logical connection, therefore you can display any desired view in any perspective whenever you like. For PHP, Eclipse offers two perspectives:
  • PHP Perspective: Provides a set of views used for the development stage
  • PHP Debug Perspective: Provides a set of views used for debugging
You can activate either perspective from the Window → Open Perspective → Other menu. Selecting that opens a wizard that displays all the available perspectives. Select the one you want, and click OK. For now, activate the PHP perspective, which will reveal the following PHP-dedicated views:

  • PHP Explorer: This tree view represents a PHP application.
  • PHP Functions: This view contains a list with core PHP functions. By double-clicking on a function you can insert it in your PHP code, while right-clicking on a function and selecting the "Open Manual" option, opens the PHP manual directly to the corresponding section.
  •  
    Figure 12. Activate the PHP Perspective: The figure shows the activated views in Eclipse's PHP perspective.
  • PHP Project Outline: Represents an outline view useful for large projects that's split into three sections: Classes, Constants and Functions.
  • Parameter Stack: Displays parameters when stepping into a function during the debugging process.
  • Browser Output: Shows the browser output.
  • Debug Output: Shows debug output.
You can activate any of these views from the Window → Show View → Other → PHP Tools menu item. As an example, activate all of them under the PHP perspective, and then drag and drop to arrange them in a convenient manner, as in Figure 12. Eclipse remembers these settings, so the arrangement in Figure 12 will reappear the next time you use the PHP perspective.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap