Add a PHP nature to an Eclipse Flex project

Add a PHP nature to an Eclipse Flex project

Let me start by saying for those that found this post and want the quick answer:

  1. Add “org.eclipse.php.core.PHPNature” to the “.project” file.
  2. Refresh your project in Eclipse and you’re done (Eclipse will add the remaining needed files and elements to your .project file automatically).

For those of you that want it in detailed version and some extra tips, read on….

It’s pretty easy to add an Adobe Flex project nature to an existing PHP project in Eclipse as you can see below (right click on your PHP Project)

php_nature

… but going the other way around and adding a PHP nature to a Flex Project can be a little more tedious but not all that bad. I’ll be using Eclipse 3.4 with the Flex 3 Plugin and PDT 2.0 for this example.  It won’t matter if you’re on Mac or Windows.  Here’s how to do it:

  1. I’ll start from scratch by creating a Flex 3 project in Eclipse named “My Flex Project”.
  2. Next, locate your “.project” file and open itprojectFileLocation
  3. Now in the .project file you’ll need to add “org.eclipse.php.core.PHPNature” to the block shown circled in red below and then save it.Screen shot 2009-09-29 at 12.24.30 PM
  4. In Eclipse, right-click on the project and select “Refresh”.   You’re done!

Now if you go back and look at the .project file we edited in step 3 above, you’ll see that Eclipse added extra elements for us automatically.  You’ll also see that a file named “.buildpath” was added to your project directory too.

One thing I recommend is creating a separate source folder in your project to organize your PHP code and keep it isolated from your Flex code.  To do this:

  1. In Eclipse, create a folder in the root of your project.  I’ll name the folder “src_php” for this example.
  2. Right click on your project and select “properties”.  Go to “PHP Build Path” and remove the default build:Screen shot 2009-09-29 at 12.50.45 PM
  3. Keep that window open and click “Add Folder”.  Check the new folder you created for your PHP source (“src_php” in this example) and click “OK”.Screen shot 2009-09-29 at 1.01.06 PM
  4. Click “OK” in the “PHP Build Path” window and you’re finished!Screen shot 2009-09-29 at 1.03.29 PM

The good thing about doing this is that your folders like “html-template” won’t be taken for PHP packages.  If you switch between the Flex and PHP persepective you’ll also notice that the associated source folder always positions itself at the top of the directory structure (not a big deal but it’s nice).

NOTE: If you want to rename your Flex “src” folder and are having trouble let me know and I’ll add how to do that.  It takes a small tweak in the .actionSriptProperties file after you rename/refactor the src folder.   You’ll also have to reset the default mxml application file.