http://www.developer.com/lang/php/get-more-efficient-on-eclipse-pdt.html

Back to article

10 Powerful PDT Tools, Tips and Tricks for PHP Developers


March 8, 2011

The best developers are efficient developers, individuals who have figured out how to write the largest amount of quality code in the shortest possible period of time. One of the easiest ways to become a more efficient developers is by choosing and mastering an integrated development environment (IDE). Of course, exactly which IDE you should use has long been a favorite subject of heated debate. Within the PHP community, however, there's little doubt that the PHP Developer Tools (PDT) framework for Eclipse has emerged as one of the most popular open source development environments. I use PDT and happen to think it a superb solution for rapid PHP development.

In this article I'll share 10 different tools, tips and tricks worthy of consideration if you've recently adopted PDT as your IDE. Of course, we'd love to hear about your own tips, so be sure to add them to the comments section at the bottom of this article!

1. PDT Tip: Configure Zend Framework Code Completion

If you're using the Zend Framework, you logically should take advantage of code completion when using the various Zend Framework classes. To do so, you'll need to add the Zend Framework library directory to your project's PHP include path. Right click on your project within the PDT project explorer, choose the PHP Include Path menu item, and add the library directory path via the Libraries tab. Once added, code completion will be available. Just start typing Zend and then press the Ctrl+Space hotkey to display the completion menu!

Of course this process isn't limited to use solely with the Zend Framework. Follow the same steps to make code completion available for CakePHP, symfony, or any other framework!

2. PDT Tool: Install the Zen Coding Plugin

Hand-coding large amounts of HTML can become a very tedious task -- particularly when you're working with deeply nested elements. For instance, creating an unordered list containing five items, with each item using a bold tag involves either a lot of typing or copying/pasting. I was looking for a faster way to barrel through the creation of these sorts of HTML structures and was lucky enough to find Zen Coding, an incredibly intuitive solution for rapidly generating HTML and CSS. Once the Zen Coding editor plugin (all major editors are supported) is installed, creating the aforementioned list is as simple as typing out the following sequence and pressing the ctrl+e shortcut:

ul>li*5>b

After pressing ctrl+e, the following structure will be generated:

Adding Zen Coding support to PDT is easy, simply install Sergey Chikuyonok's eclipse-zencoding plugin. Just follow the instructions found in the project README, restart PDT, and you can start writing HTML code faster than you ever imagined!

If you're looking for a comprehensive Zen Coding tutorial, check out Zen Coding and the Art of Rapid HTML Authoring.

3. PDT Tip: Take Advantage of PHP Templates

PDT can save you a great deal of typing thanks to the almost 50 PHP code templates made available to the IDE. Use these templates to quickly add common syntactical structures such as PHP classes, switch statements, and block comments. For instance, if you want to create a new PHP class, start typing class and press the ctrl+space hotkey. From the popup menu, choose class - class statement and press return. The following structure will be added to the file:

class class_name {
	function function_name() {
		;
	}
}

Once added, you'll be able to quickly add the class name and method name as PDT will use placeholders for these values and allow you to type the former and pressing tab to move to the next location.

To view a complete list of available templates, navigate to Window > Preferences > PHP > Editor > Templates. Here you can also further enhance PDT's templating feature by adding your own!

4. PDT Trick: Use the PHP Functions Menu

I've used PHP's date() function more than 1000 times during the past decade, but to this day I can't recall the purpose of the many date formatting arguments it supports. If you can't remember a particular function or the arguments it supports, open the PHP Functions view (Window > Show View > PHP Functions). Unfortunately, a hotkey isn't assigned to this particular view by default, but you can easily add one by navigating to Window > Preferences > General > Keys and then scrolling to Show View (View: PHP Functions).

5. PDT Trick: Integrate a Local PHP Manual

Building upon the previous tip, you'll often need to dig a bit deeper into a function's capabilities, going beyond merely reviewing the function's name and argument signature. You can review a function's manual entry by right clicking on its PHP Functions view listing. The default behavior is to retrieve the page found at www.php.net. You have the option of streamlining this process by telling PDT to instead use a local version of the manual. To use a local version, download the PHP manual (many files version) from http://www.php.net/download-docs.php, and save it to a convenient location on your laptop. Next, open PDT and navigate to Window > Preferences > PHP > PHP Manual. Add the new manual location, making sure to set the File Extension setting to HTML.

6. PDT Tip: Integrate External Tools

Development utilities such as PHPDoc and PHPUnit are incredibly useful, but at this time PDT plugins aren't readily available. You can however execute these utilities by configuring them as external tools. To do so, click on the External Tools icon located in the main toolbar and select the External Tools Configurations… menu item. There you will be able to create a new external tool reference, defining a tool name, location, and passing along any arguments. Once defined, you'll be able to execute the tool by again clicking on the External Tools icon and choosing the tool from the list.

7. PDT Tool: Install the Zend Debugger Plugin

If you installed PDT as an Eclipse plugin rather than installing the Eclipse PDT All In One package, you'll probably also want to install the Zend Debugger. Install the Zend Debugger client by adding the http://downloads.zend.com/pdt update site to your list of Eclipse update sites (Help > Install New Software…). Install the Zend Debugger and restart PDT.

Once installed, you'll be able to access the PHP Debug Perspective. Via this perspective, you'll be able to set breakpoints, trace variables, and view debug output.

8. PDT Trick: Add Git Integration

I'm a big fan of Git. It's the most intuitive and least intrusive of the many version control systems I've used over the years. If you're a Git user, you can manage your project repositories from directly within the PDT interface using the EGit plugin. Via this interface you can commit files, add log messages, create branches, add remotes, and do everything else you've grown accustomed to accomplishing via the command-line client. Although still officially a beta release, I've found EGit to be very stable and in just a few short weeks it has become an indispensable part of my daily workflow.

9. PDT Tool: Manage MySQL Databases with QuantumDB

Although I generally prefer to manage my MySQL databases either via the command-line client or phpMyAdmin, it's possible to peruse and manipulate your databases via the QuantumDB plugin. Once installed, you'll be able to review schemas, add and manipulate records, and execute SQL statements--all without having to leave the PDT environment.

10. PDT Tip: Download the Eclipse Cheat Sheet

While all of the tips, tricks and tools described so far are indeed useful, much of the productivity gained as a result of using an IDE such as Eclipse is going to come by way of your ability to quickly navigate the environment. Consider printing off one of the many available cheat sheets that highlight popular keyboard shortcuts, such as DZone's Getting Started with Eclipse.

About the Author

Jason Gilmore--Contributing Editor, PHP--is the founder of EasyPHPWebsites.com, and author of the popular book, "Easy PHP Websites with the Zend Framework". Jason is a cofounder and speaker chair of CodeMash, a nonprofit organization tasked with hosting an annual namesake developer's conference, and was a member of the 2008 MySQL Conference speaker selection board.

Sitemap | Contact Us